{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "db35848e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import re\n",
    "import os\n",
    "import json\n",
    "import time\n",
    "import pandas as pd\n",
    "from bs4 import BeautifulSoup as bs\n",
    "from dataclasses import dataclass\n",
    "from collections import namedtuple, defaultdict"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02d05bd0",
   "metadata": {},
   "source": [
    "# 1. ОПИСАНИЕ\n",
    "\n",
    "У Мосбиржи есть открытый интерфейс для получения различных рыночных данных. Он распологается по адресу http://iss.moex.com/iss/reference. Но к сожалению, его описание не идеально. Частично описано в документации https://fs.moex.com/files/6523. Часть поинтов недоступны без оформления подписки. Часть из них не работаеат, а их общее число заходит за 150 шт.\n",
    "\n",
    "Большинству достаточно использовать несколько поинтов - получения истории торгов и описания инструментов.\n",
    "Для качественной аналитики этих данных может быть недостаточно. А для некоторых задач, этого критически недостаточно (например, в выялвении фрода, инсайда и манипулирования на финансовых рынках). Приведем часть интересных кейсов:\n",
    "\n",
    "1. Инсайдеры могут заблоговременно совершать сделки перед раскрытием существенных факторов;\n",
    "2. Неликивидные бумаги посредством сделок с договоренностью могут переводить в ликвидные с целью соответствия правилам инвест. деклараций, привлечения публики, массовых скупок/распродаж, завышения залога по сделкам РЕПО и прочего (и вплоть до завышения/занижения цены при SPO/обратных выкупах);\n",
    "3. Часть бумаг (как правило неликвдиных бондов) могут целенаправленно завышать в цене, с целью извлечения дополнительных комиссионных от объема/доходности средств в управлении;\n",
    "4. Обход законодательных ограничений или лимитов участника торгов (например, продажа ФИ внутри одной УК);\n",
    "5. Подгод рыночных цен под будущую крупную внебиржевую сделку (вне основных торгов). Объемы таких сделок могут значительно завышать обороты рынка данной бумаги;\n",
    "6. Влияние на цены фиксинга связанных ФИ/ПФИ/курсов валют. Крупные остаки ПФИ могут стимулировать к совершению сделок искажающих цены на спот рынке (или наоборот, но реже); \n",
    "7. Искусственное искажение спроса и предложения, злоупотребление правами маркет-мейкера;\n",
    "8. Изменение объемов свободной ликвидности (резкие обвалы на рынке часто начинаются с недостатка ликвидности: распрадажа активов для покрытия текущих обязательств). Поэтому и нужно постоянно мониторить здоровье финансовой сферы;\n",
    "9. Внутренние мошенничества: совершение опережающих сделок перед крупными заявками, нарушение приниципа китайских стен;\n",
    "10. Подковерные игры бенефициров.\n",
    "11. Непрофессиональное исполнение поручений и т.п. \n",
    "\n",
    "Это далеко не весь список кейсов. Но уже из этого следует, что нужно следить не только за историей основных торгов, но и за показателями других площадок, ПФИ, РЕПО, фиксингом, ставками, валютой, вложениями фондов, новостями и т.д.\n",
    "\n",
    "Лучше данные - это история логов заявок, но, к сожалению они доступны только при оформлении подписки.\n",
    "\n",
    "\n",
    "**Весь последующий анализ проводится для разработки библиотеки для удобной работы с апи Мосбиржи**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8a609c65",
   "metadata": {},
   "outputs": [],
   "source": [
    "root_url = \"http://iss.moex.com\"\n",
    "docs_url = \"/iss/reference\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9a4e4021",
   "metadata": {},
   "outputs": [],
   "source": [
    "req = requests.get(root_url + docs_url)\n",
    "soup = bs(req.content).body.dl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c1f67664",
   "metadata": {},
   "outputs": [],
   "source": [
    "@dataclass\n",
    "class MoexApi:\n",
    "    url_faq: str\n",
    "    url_template: str\n",
    "    description: str = ''"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "084c952b",
   "metadata": {},
   "source": [
    "# 2. GET API MOEX"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4855c90a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# GET API\n",
    "FINAL_DATA = []\n",
    "tmp_list = []\n",
    "for el in soup.next_elements:\n",
    "    if el.name == \"dt\":  # href in child element \"a\"\n",
    "        a = el.contents[0]\n",
    "        tmp_list = [\n",
    "            root_url + docs_url + a.attrs['href'].replace('.', ''),\n",
    "            root_url + a.text\n",
    "        ]\n",
    "    \n",
    "    elif el.name == \"p\":  # Description\n",
    "        tmp_list.append(el.text.strip().replace('\\n', ''))\n",
    "        if len(tmp_list) == 3:\n",
    "            FINAL_DATA.append(\n",
    "                MoexApi(url_faq=tmp_list[0], url_template=tmp_list[1], description=tmp_list[2])\n",
    "            )\n",
    "            tmp_list = []\n",
    "        else:\n",
    "            print(tmp_list)\n",
    "            raise Exception(\"SOMETHING WENT WRONG\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cec3dc57",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Quantity of endpoint = 151\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/5', url_template='http://iss.moex.com/iss/securities', description='Список бумаг торгуемых на московской бирже.'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/13', url_template='http://iss.moex.com/iss/securities/[security]', description='Получить спецификацию инструмента. Например: https://iss.moex.com/iss/securities/IMOEX.xml'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/160', url_template='http://iss.moex.com/iss/securities/[security]/indices', description='Список индексов в которые входит бумага'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/214', url_template='http://iss.moex.com/iss/securities/[security]/aggregates', description='Агрегированные итоги торгов за дату по рынкам'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/823', url_template='http://iss.moex.com/iss/engines/[engine]/markets/[market]/secstats', description='Промежуточные \"Итоги дня\".Только для фондового рынка')]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print('Quantity of endpoint =', len(FINAL_DATA))\n",
    "FINAL_DATA[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f91f29d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# GET ENTITIES (GLOBALS)\n",
    "ENTITIES = defaultdict(list)\n",
    "\n",
    "for num, api in enumerate(FINAL_DATA):\n",
    "    entities = list(map(lambda entity: entity[1:-1], re.findall(r'\\[\\w*\\]', api.url_template)))\n",
    "    \n",
    "    if entities:\n",
    "        api.url_template = api.url_template.replace('[', '{').replace(']', '}')\n",
    "        for entity in entities:\n",
    "            ENTITIES[entity].append(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7cfad46",
   "metadata": {},
   "source": [
    "# 3. CHECK Entities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4ba995aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'asset': '❌',\n",
       " 'board': '❌',\n",
       " 'boardgroup': '❌',\n",
       " 'collection': '❌',\n",
       " 'datatype': '❌',\n",
       " 'engine': '❌',\n",
       " 'event_id': '❌',\n",
       " 'indexid': '❌',\n",
       " 'market': '❌',\n",
       " 'news_id': '❌',\n",
       " 'period': '❌',\n",
       " 'report_name': '❌',\n",
       " 'securities': '❌',\n",
       " 'security': '❌',\n",
       " 'securitygroup': '❌',\n",
       " 'session': '❌',\n",
       " 'ticker': '❌',\n",
       " 'year': '❌'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ✅❌\n",
    "CHECK_ENTITY = {entity: '❌' for entity in sorted(ENTITIES.keys())}\n",
    "ENTITY_DESCRIPTIONS = {}\n",
    "CHECK_ENTITY"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "80bf56c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/877', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/options/assets/{asset}', description='Опционные серии'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/879', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/options/assets/{asset}/volumes', description='Объем торгов для опционной серии'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/881', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/options/assets/{asset}/optionboard', description='Доска опционов'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/883', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/options/assets/{asset}/openpositions', description='Открытые позиции по опционной серии'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/885', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/options/assets/{asset}/turnovers', description='Объем торгов для опционной серии')]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# NEXT CELLS - Analitics\n",
    "[FINAL_DATA[inx] for inx in ENTITIES['asset']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "d66989e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "ENTITY_DESCRIPTIONS['asset'] = \"Базовый актив опциона\"  # Требуется анализ. Скорее всего БА в справочниках опционов"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e203a70d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['engines', 'markets', 'boards', 'boardgroups', 'durations', 'securitytypes', 'securitygroups', 'securitycollections'])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Получить глобальные справочники ISS. Например: https://iss.moex.com/iss/index.xml\n",
    "global_entity = requests.get(\"https://iss.moex.com/iss/index.json\").json()\n",
    "global_entity.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "45b2b5c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "engines \n",
      " ['id', 'name', 'title'] \n",
      "\n",
      "markets \n",
      " ['id', 'trade_engine_id', 'trade_engine_name', 'trade_engine_title', 'market_name', 'market_title', 'market_id', 'marketplace', 'is_otc', 'has_history_files', 'has_history_trades_files', 'has_trades', 'has_history', 'has_candles', 'has_orderbook', 'has_tradingsession', 'has_extra_yields', 'has_delay'] \n",
      "\n",
      "boards \n",
      " ['id', 'board_group_id', 'engine_id', 'market_id', 'boardid', 'board_title', 'is_traded', 'has_candles', 'is_primary'] \n",
      "\n",
      "boardgroups \n",
      " ['id', 'trade_engine_id', 'trade_engine_name', 'trade_engine_title', 'market_id', 'market_name', 'name', 'title', 'is_default', 'board_group_id', 'is_traded', 'is_order_driven', 'category'] \n",
      "\n",
      "durations \n",
      " ['interval', 'duration', 'days', 'title', 'hint'] \n",
      "\n",
      "securitytypes \n",
      " ['id', 'trade_engine_id', 'trade_engine_name', 'trade_engine_title', 'security_type_name', 'security_type_title', 'security_group_name', 'stock_type'] \n",
      "\n",
      "securitygroups \n",
      " ['id', 'name', 'title', 'is_hidden'] \n",
      "\n",
      "securitycollections \n",
      " ['id', 'name', 'title', 'security_group_id'] \n",
      "\n"
     ]
    }
   ],
   "source": [
    "for key, val in global_entity.items():\n",
    "    print(key, '\\n',  val['columns'], '\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1b7ca7bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>trade_engine_id</th>\n",
       "      <th>trade_engine_name</th>\n",
       "      <th>trade_engine_title</th>\n",
       "      <th>market_title</th>\n",
       "      <th>market_id</th>\n",
       "      <th>marketplace</th>\n",
       "      <th>is_otc</th>\n",
       "      <th>has_history_files</th>\n",
       "      <th>has_history_trades_files</th>\n",
       "      <th>has_trades</th>\n",
       "      <th>has_history</th>\n",
       "      <th>has_candles</th>\n",
       "      <th>has_orderbook</th>\n",
       "      <th>has_tradingsession</th>\n",
       "      <th>has_extra_yields</th>\n",
       "      <th>has_delay</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>market_name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>index</th>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Индексы фондового рынка</td>\n",
       "      <td>5</td>\n",
       "      <td>INDICES</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>shares</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Рынок акций</td>\n",
       "      <td>1</td>\n",
       "      <td>MXSE</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bonds</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Рынок облигаций</td>\n",
       "      <td>2</td>\n",
       "      <td>MXSE</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ndm</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Режим переговорных сделок</td>\n",
       "      <td>4</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>otc</th>\n",
       "      <td>29</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>ОТС</td>\n",
       "      <td>29</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ccp</th>\n",
       "      <td>27</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>РЕПО с ЦК</td>\n",
       "      <td>27</td>\n",
       "      <td>MXSE</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>deposit</th>\n",
       "      <td>35</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Депозиты с ЦК</td>\n",
       "      <td>35</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>repo</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Рынок сделок РЕПО</td>\n",
       "      <td>3</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>qnv</th>\n",
       "      <td>28</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Квал. инвесторы</td>\n",
       "      <td>28</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mamc</th>\n",
       "      <td>36</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Мультивалютный рынок смешанных активов</td>\n",
       "      <td>36</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>foreignshares</th>\n",
       "      <td>47</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Иностранные ц.б.</td>\n",
       "      <td>47</td>\n",
       "      <td>MXSE</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>foreignndm</th>\n",
       "      <td>49</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Иностранные ц.б. РПС</td>\n",
       "      <td>49</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>moexboard</th>\n",
       "      <td>33</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>MOEX Board</td>\n",
       "      <td>33</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>gcc</th>\n",
       "      <td>46</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>РЕПО с ЦК с КСУ</td>\n",
       "      <td>46</td>\n",
       "      <td>MXSE</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>credit</th>\n",
       "      <td>54</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Рынок кредитов</td>\n",
       "      <td>54</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>selt</th>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "      <td>currency</td>\n",
       "      <td>Валютный рынок</td>\n",
       "      <td>Биржевые сделки с ЦК</td>\n",
       "      <td>10</td>\n",
       "      <td>MXCX</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures</th>\n",
       "      <td>34</td>\n",
       "      <td>3</td>\n",
       "      <td>currency</td>\n",
       "      <td>Валютный рынок</td>\n",
       "      <td>Поставочные фьючерсы</td>\n",
       "      <td>34</td>\n",
       "      <td>MXCX</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>index</th>\n",
       "      <td>41</td>\n",
       "      <td>3</td>\n",
       "      <td>currency</td>\n",
       "      <td>Валютный рынок</td>\n",
       "      <td>Валютный фиксинг</td>\n",
       "      <td>41</td>\n",
       "      <td>FIXING</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>otc</th>\n",
       "      <td>45</td>\n",
       "      <td>3</td>\n",
       "      <td>currency</td>\n",
       "      <td>Валютный рынок</td>\n",
       "      <td>Внебиржевой</td>\n",
       "      <td>45</td>\n",
       "      <td>MXCX</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>main</th>\n",
       "      <td>12</td>\n",
       "      <td>4</td>\n",
       "      <td>futures</td>\n",
       "      <td>Срочный рынок</td>\n",
       "      <td>Срочные инструменты</td>\n",
       "      <td>12</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>forts</th>\n",
       "      <td>22</td>\n",
       "      <td>4</td>\n",
       "      <td>futures</td>\n",
       "      <td>Срочный рынок</td>\n",
       "      <td>ФОРТС</td>\n",
       "      <td>22</td>\n",
       "      <td>FORTS</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>options</th>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>futures</td>\n",
       "      <td>Срочный рынок</td>\n",
       "      <td>Опционы ФОРТС</td>\n",
       "      <td>24</td>\n",
       "      <td>OPTIONS</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>fortsiqs</th>\n",
       "      <td>37</td>\n",
       "      <td>4</td>\n",
       "      <td>futures</td>\n",
       "      <td>Срочный рынок</td>\n",
       "      <td>Фьючерсы IQS</td>\n",
       "      <td>37</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>optionsiqs</th>\n",
       "      <td>38</td>\n",
       "      <td>4</td>\n",
       "      <td>futures</td>\n",
       "      <td>Срочный рынок</td>\n",
       "      <td>Опционы IQS</td>\n",
       "      <td>38</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>index</th>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "      <td>state</td>\n",
       "      <td>Рынок ГЦБ (размещение)</td>\n",
       "      <td>Индексы ГКО/ОФЗ</td>\n",
       "      <td>9</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bonds</th>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>state</td>\n",
       "      <td>Рынок ГЦБ (размещение)</td>\n",
       "      <td>Облигации ГЦБ</td>\n",
       "      <td>6</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>repo</th>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>state</td>\n",
       "      <td>Рынок ГЦБ (размещение)</td>\n",
       "      <td>Междилерское РЕПО</td>\n",
       "      <td>7</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ndm</th>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>state</td>\n",
       "      <td>Рынок ГЦБ (размещение)</td>\n",
       "      <td>Внесистемные сделки</td>\n",
       "      <td>8</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bonds</th>\n",
       "      <td>39</td>\n",
       "      <td>7</td>\n",
       "      <td>offboard</td>\n",
       "      <td>ОТС-система</td>\n",
       "      <td>Облигации</td>\n",
       "      <td>39</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>shares</th>\n",
       "      <td>1257</td>\n",
       "      <td>1012</td>\n",
       "      <td>otc</td>\n",
       "      <td>ОТС с ЦК</td>\n",
       "      <td>Акции</td>\n",
       "      <td>1257</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>bonds</th>\n",
       "      <td>1013</td>\n",
       "      <td>1012</td>\n",
       "      <td>otc</td>\n",
       "      <td>ОТС с ЦК</td>\n",
       "      <td>Облигации</td>\n",
       "      <td>1013</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sharesndm</th>\n",
       "      <td>1262</td>\n",
       "      <td>1012</td>\n",
       "      <td>otc</td>\n",
       "      <td>ОТС с ЦК</td>\n",
       "      <td>Акции с ЦК</td>\n",
       "      <td>1262</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ndm</th>\n",
       "      <td>1014</td>\n",
       "      <td>1012</td>\n",
       "      <td>otc</td>\n",
       "      <td>ОТС с ЦК</td>\n",
       "      <td>Облигации c ЦК</td>\n",
       "      <td>1014</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>nonresndm</th>\n",
       "      <td>1015</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Режим переговорных сделок (нерезиденты)</td>\n",
       "      <td>1015</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>nonresrepo</th>\n",
       "      <td>1017</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Рынок РЕПО (нерезиденты)</td>\n",
       "      <td>1017</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>nonresccp</th>\n",
       "      <td>1019</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Рынок РЕПО с ЦК (нерезиденты)</td>\n",
       "      <td>1019</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures</th>\n",
       "      <td>18</td>\n",
       "      <td>5</td>\n",
       "      <td>commodity</td>\n",
       "      <td>Товарный рынок</td>\n",
       "      <td>Секция стандартных контрактов АО НТБ</td>\n",
       "      <td>18</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>grain</th>\n",
       "      <td>20</td>\n",
       "      <td>6</td>\n",
       "      <td>interventions</td>\n",
       "      <td>Товарные интервенции</td>\n",
       "      <td>Интервенции по зерну</td>\n",
       "      <td>20</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sugar</th>\n",
       "      <td>51</td>\n",
       "      <td>9</td>\n",
       "      <td>agro</td>\n",
       "      <td>Агро</td>\n",
       "      <td>Торги сахаром</td>\n",
       "      <td>51</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>auctions</th>\n",
       "      <td>1031</td>\n",
       "      <td>9</td>\n",
       "      <td>agro</td>\n",
       "      <td>Агро</td>\n",
       "      <td>Аукционы НТБ</td>\n",
       "      <td>1031</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>buyauctions</th>\n",
       "      <td>1084</td>\n",
       "      <td>9</td>\n",
       "      <td>agro</td>\n",
       "      <td>Агро</td>\n",
       "      <td>Закупочные аукционы НТБ</td>\n",
       "      <td>1084</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>standard</th>\n",
       "      <td>23</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Standard</td>\n",
       "      <td>23</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>classica</th>\n",
       "      <td>25</td>\n",
       "      <td>1</td>\n",
       "      <td>stock</td>\n",
       "      <td>Фондовый рынок и рынок депозитов</td>\n",
       "      <td>Classica</td>\n",
       "      <td>25</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 id  trade_engine_id trade_engine_name  \\\n",
       "market_name                                              \n",
       "index             5                1             stock   \n",
       "shares            1                1             stock   \n",
       "bonds             2                1             stock   \n",
       "ndm               4                1             stock   \n",
       "otc              29                1             stock   \n",
       "ccp              27                1             stock   \n",
       "deposit          35                1             stock   \n",
       "repo              3                1             stock   \n",
       "qnv              28                1             stock   \n",
       "mamc             36                1             stock   \n",
       "foreignshares    47                1             stock   \n",
       "foreignndm       49                1             stock   \n",
       "moexboard        33                1             stock   \n",
       "gcc              46                1             stock   \n",
       "credit           54                1             stock   \n",
       "selt             10                3          currency   \n",
       "futures          34                3          currency   \n",
       "index            41                3          currency   \n",
       "otc              45                3          currency   \n",
       "main             12                4           futures   \n",
       "forts            22                4           futures   \n",
       "options          24                4           futures   \n",
       "fortsiqs         37                4           futures   \n",
       "optionsiqs       38                4           futures   \n",
       "index             9                2             state   \n",
       "bonds             6                2             state   \n",
       "repo              7                2             state   \n",
       "ndm               8                2             state   \n",
       "bonds            39                7          offboard   \n",
       "shares         1257             1012               otc   \n",
       "bonds          1013             1012               otc   \n",
       "sharesndm      1262             1012               otc   \n",
       "ndm            1014             1012               otc   \n",
       "nonresndm      1015                1             stock   \n",
       "nonresrepo     1017                1             stock   \n",
       "nonresccp      1019                1             stock   \n",
       "futures          18                5         commodity   \n",
       "grain            20                6     interventions   \n",
       "sugar            51                9              agro   \n",
       "auctions       1031                9              agro   \n",
       "buyauctions    1084                9              agro   \n",
       "standard         23                1             stock   \n",
       "classica         25                1             stock   \n",
       "\n",
       "                             trade_engine_title  \\\n",
       "market_name                                       \n",
       "index          Фондовый рынок и рынок депозитов   \n",
       "shares         Фондовый рынок и рынок депозитов   \n",
       "bonds          Фондовый рынок и рынок депозитов   \n",
       "ndm            Фондовый рынок и рынок депозитов   \n",
       "otc            Фондовый рынок и рынок депозитов   \n",
       "ccp            Фондовый рынок и рынок депозитов   \n",
       "deposit        Фондовый рынок и рынок депозитов   \n",
       "repo           Фондовый рынок и рынок депозитов   \n",
       "qnv            Фондовый рынок и рынок депозитов   \n",
       "mamc           Фондовый рынок и рынок депозитов   \n",
       "foreignshares  Фондовый рынок и рынок депозитов   \n",
       "foreignndm     Фондовый рынок и рынок депозитов   \n",
       "moexboard      Фондовый рынок и рынок депозитов   \n",
       "gcc            Фондовый рынок и рынок депозитов   \n",
       "credit         Фондовый рынок и рынок депозитов   \n",
       "selt                             Валютный рынок   \n",
       "futures                          Валютный рынок   \n",
       "index                            Валютный рынок   \n",
       "otc                              Валютный рынок   \n",
       "main                              Срочный рынок   \n",
       "forts                             Срочный рынок   \n",
       "options                           Срочный рынок   \n",
       "fortsiqs                          Срочный рынок   \n",
       "optionsiqs                        Срочный рынок   \n",
       "index                    Рынок ГЦБ (размещение)   \n",
       "bonds                    Рынок ГЦБ (размещение)   \n",
       "repo                     Рынок ГЦБ (размещение)   \n",
       "ndm                      Рынок ГЦБ (размещение)   \n",
       "bonds                               ОТС-система   \n",
       "shares                                 ОТС с ЦК   \n",
       "bonds                                  ОТС с ЦК   \n",
       "sharesndm                              ОТС с ЦК   \n",
       "ndm                                    ОТС с ЦК   \n",
       "nonresndm      Фондовый рынок и рынок депозитов   \n",
       "nonresrepo     Фондовый рынок и рынок депозитов   \n",
       "nonresccp      Фондовый рынок и рынок депозитов   \n",
       "futures                          Товарный рынок   \n",
       "grain                      Товарные интервенции   \n",
       "sugar                                      Агро   \n",
       "auctions                                   Агро   \n",
       "buyauctions                                Агро   \n",
       "standard       Фондовый рынок и рынок депозитов   \n",
       "classica       Фондовый рынок и рынок депозитов   \n",
       "\n",
       "                                          market_title  market_id marketplace  \\\n",
       "market_name                                                                     \n",
       "index                          Индексы фондового рынка          5     INDICES   \n",
       "shares                                     Рынок акций          1        MXSE   \n",
       "bonds                                  Рынок облигаций          2        MXSE   \n",
       "ndm                          Режим переговорных сделок          4        None   \n",
       "otc                                                ОТС         29        None   \n",
       "ccp                                          РЕПО с ЦК         27        MXSE   \n",
       "deposit                                  Депозиты с ЦК         35        None   \n",
       "repo                                 Рынок сделок РЕПО          3        None   \n",
       "qnv                                    Квал. инвесторы         28        None   \n",
       "mamc            Мультивалютный рынок смешанных активов         36        None   \n",
       "foreignshares                         Иностранные ц.б.         47        MXSE   \n",
       "foreignndm                        Иностранные ц.б. РПС         49        None   \n",
       "moexboard                                   MOEX Board         33        None   \n",
       "gcc                                    РЕПО с ЦК с КСУ         46        MXSE   \n",
       "credit                                  Рынок кредитов         54        None   \n",
       "selt                              Биржевые сделки с ЦК         10        MXCX   \n",
       "futures                           Поставочные фьючерсы         34        MXCX   \n",
       "index                                 Валютный фиксинг         41      FIXING   \n",
       "otc                                        Внебиржевой         45        MXCX   \n",
       "main                               Срочные инструменты         12        None   \n",
       "forts                                            ФОРТС         22       FORTS   \n",
       "options                                  Опционы ФОРТС         24     OPTIONS   \n",
       "fortsiqs                                  Фьючерсы IQS         37        None   \n",
       "optionsiqs                                 Опционы IQS         38        None   \n",
       "index                                  Индексы ГКО/ОФЗ          9        None   \n",
       "bonds                                    Облигации ГЦБ          6        None   \n",
       "repo                                 Междилерское РЕПО          7        None   \n",
       "ndm                                Внесистемные сделки          8        None   \n",
       "bonds                                        Облигации         39        None   \n",
       "shares                                           Акции       1257        None   \n",
       "bonds                                        Облигации       1013        None   \n",
       "sharesndm                                   Акции с ЦК       1262        None   \n",
       "ndm                                     Облигации c ЦК       1014        None   \n",
       "nonresndm      Режим переговорных сделок (нерезиденты)       1015        None   \n",
       "nonresrepo                    Рынок РЕПО (нерезиденты)       1017        None   \n",
       "nonresccp                Рынок РЕПО с ЦК (нерезиденты)       1019        None   \n",
       "futures           Секция стандартных контрактов АО НТБ         18        None   \n",
       "grain                             Интервенции по зерну         20        None   \n",
       "sugar                                    Торги сахаром         51        None   \n",
       "auctions                                  Аукционы НТБ       1031        None   \n",
       "buyauctions                    Закупочные аукционы НТБ       1084        None   \n",
       "standard                                      Standard         23        None   \n",
       "classica                                      Classica         25        None   \n",
       "\n",
       "               is_otc  has_history_files  has_history_trades_files  \\\n",
       "market_name                                                          \n",
       "index               0                1.0                       0.0   \n",
       "shares              0                1.0                       1.0   \n",
       "bonds               0                1.0                       1.0   \n",
       "ndm                 0                1.0                       1.0   \n",
       "otc                 0                0.0                       0.0   \n",
       "ccp                 0                1.0                       1.0   \n",
       "deposit             0                1.0                       0.0   \n",
       "repo                0                1.0                       1.0   \n",
       "qnv                 0                1.0                       1.0   \n",
       "mamc                0                1.0                       1.0   \n",
       "foreignshares       0                1.0                       1.0   \n",
       "foreignndm          0                1.0                       1.0   \n",
       "moexboard           0                1.0                       0.0   \n",
       "gcc                 0                1.0                       1.0   \n",
       "credit              0                0.0                       0.0   \n",
       "selt                0                1.0                       1.0   \n",
       "futures             0                1.0                       0.0   \n",
       "index               0                0.0                       0.0   \n",
       "otc                 0                1.0                       1.0   \n",
       "main                0                1.0                       1.0   \n",
       "forts               0                1.0                       1.0   \n",
       "options             0                1.0                       1.0   \n",
       "fortsiqs            0                0.0                       0.0   \n",
       "optionsiqs          0                0.0                       0.0   \n",
       "index               0                1.0                       0.0   \n",
       "bonds               0                1.0                       1.0   \n",
       "repo                0                1.0                       1.0   \n",
       "ndm                 0                1.0                       1.0   \n",
       "bonds               1                1.0                       0.0   \n",
       "shares              1                NaN                       NaN   \n",
       "bonds               1                0.0                       0.0   \n",
       "sharesndm           1                NaN                       NaN   \n",
       "ndm                 1                0.0                       0.0   \n",
       "nonresndm           0                1.0                       1.0   \n",
       "nonresrepo          0                1.0                       1.0   \n",
       "nonresccp           0                1.0                       1.0   \n",
       "futures             0                1.0                       0.0   \n",
       "grain               0                0.0                       0.0   \n",
       "sugar               0                0.0                       0.0   \n",
       "auctions            0                0.0                       0.0   \n",
       "buyauctions         0                0.0                       0.0   \n",
       "standard            0                1.0                       1.0   \n",
       "classica            0                1.0                       1.0   \n",
       "\n",
       "               has_trades  has_history  has_candles  has_orderbook  \\\n",
       "market_name                                                          \n",
       "index                 1.0          1.0            1            0.0   \n",
       "shares                1.0          1.0            1            1.0   \n",
       "bonds                 1.0          1.0            1            1.0   \n",
       "ndm                   1.0          1.0            0            0.0   \n",
       "otc                   0.0          1.0            0            0.0   \n",
       "ccp                   1.0          1.0            1            1.0   \n",
       "deposit               0.0          1.0            0            0.0   \n",
       "repo                  1.0          1.0            0            0.0   \n",
       "qnv                   1.0          1.0            1            0.0   \n",
       "mamc                  1.0          1.0            0            0.0   \n",
       "foreignshares         1.0          1.0            1            1.0   \n",
       "foreignndm            1.0          1.0            0            0.0   \n",
       "moexboard             0.0          1.0            0            0.0   \n",
       "gcc                   1.0          1.0            1            1.0   \n",
       "credit                1.0          0.0            1            0.0   \n",
       "selt                  1.0          1.0            1            1.0   \n",
       "futures               1.0          1.0            1            1.0   \n",
       "index                 1.0          1.0            1            0.0   \n",
       "otc                   1.0          1.0            0            0.0   \n",
       "main                  1.0          1.0            1            1.0   \n",
       "forts                 1.0          1.0            1            1.0   \n",
       "options               1.0          1.0            1            1.0   \n",
       "fortsiqs              0.0          0.0            0            1.0   \n",
       "optionsiqs            0.0          0.0            0            0.0   \n",
       "index                 1.0          1.0            1            0.0   \n",
       "bonds                 1.0          1.0            1            1.0   \n",
       "repo                  1.0          1.0            0            0.0   \n",
       "ndm                   1.0          1.0            0            0.0   \n",
       "bonds                 0.0          1.0            0            0.0   \n",
       "shares                NaN          NaN            1            NaN   \n",
       "bonds                 1.0          1.0            1            1.0   \n",
       "sharesndm             NaN          NaN            1            NaN   \n",
       "ndm                   1.0          1.0            1            1.0   \n",
       "nonresndm             1.0          1.0            0            0.0   \n",
       "nonresrepo            1.0          1.0            0            0.0   \n",
       "nonresccp             1.0          1.0            1            1.0   \n",
       "futures               1.0          1.0            1            1.0   \n",
       "grain                 0.0          0.0            0            0.0   \n",
       "sugar                 1.0          1.0            1            1.0   \n",
       "auctions              1.0          0.0            0            1.0   \n",
       "buyauctions           1.0          0.0            0            1.0   \n",
       "standard              1.0          1.0            1            1.0   \n",
       "classica              1.0          1.0            1            1.0   \n",
       "\n",
       "               has_tradingsession  has_extra_yields  has_delay  \n",
       "market_name                                                     \n",
       "index                           1                 0          0  \n",
       "shares                          1                 0          1  \n",
       "bonds                           1                 1          1  \n",
       "ndm                             1                 1          1  \n",
       "otc                             0                 0          0  \n",
       "ccp                             1                 0          1  \n",
       "deposit                         0                 0          0  \n",
       "repo                            1                 0          1  \n",
       "qnv                             0                 0          1  \n",
       "mamc                            1                 0          1  \n",
       "foreignshares                   1                 0          1  \n",
       "foreignndm                      1                 0          1  \n",
       "moexboard                       0                 0          0  \n",
       "gcc                             1                 0          1  \n",
       "credit                          0                 0          1  \n",
       "selt                            0                 0          1  \n",
       "futures                         0                 0          1  \n",
       "index                           0                 0          1  \n",
       "otc                             0                 0          1  \n",
       "main                            0                 0          1  \n",
       "forts                           0                 0          1  \n",
       "options                         0                 0          1  \n",
       "fortsiqs                        0                 0          1  \n",
       "optionsiqs                      0                 0          1  \n",
       "index                           0                 0          0  \n",
       "bonds                           0                 0          1  \n",
       "repo                            0                 0          1  \n",
       "ndm                             0                 0          1  \n",
       "bonds                           0                 0          1  \n",
       "shares                          0                 0          1  \n",
       "bonds                           0                 0          1  \n",
       "sharesndm                       0                 0          1  \n",
       "ndm                             0                 0          1  \n",
       "nonresndm                       1                 1          1  \n",
       "nonresrepo                      1                 0          1  \n",
       "nonresccp                       1                 0          1  \n",
       "futures                         0                 0          1  \n",
       "grain                           0                 0          0  \n",
       "sugar                           0                 0          0  \n",
       "auctions                        0                 0          0  \n",
       "buyauctions                     0                 0          0  \n",
       "standard                        0                 0          1  \n",
       "classica                        0                 0          1  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class Globals:\n",
    "    __instance = None\n",
    "    globals_url = \"https://iss.moex.com/iss/index.json\"\n",
    "    url_index_id = \"https://iss.moex.com/iss/statistics/engines/stock/markets/index/analytics.json\"\n",
    "    \n",
    "    base_attr = namedtuple(\"base_attr\", \"main description\")\n",
    "    \n",
    "    main_attribute = {\n",
    "        \"engines\": base_attr(\"name\", \"title\"),\n",
    "        \"markets\": base_attr(\"market_name\", \"market_title\"),\n",
    "        \"boards\": base_attr(\"boardid\", \"board_title\"),\n",
    "        \"boardgroups\": base_attr(\"name\", \"title\"),\n",
    "        \"durations\": base_attr(\"interval\", \"title\"),\n",
    "        \"securitytypes\": base_attr(\"security_type_name\", \"security_type_title\"),\n",
    "        \"securitygroups\": base_attr(\"name\", \"title\"),\n",
    "        \"securitycollections\": base_attr(\"name\", \"title\"),\n",
    "    }\n",
    "    datatypes = [\"securities\", \"trades\"]\n",
    "    \n",
    "    report_names = pd.DataFrame(\n",
    "        data=[\n",
    "            [\n",
    "                \"numtrades\", \n",
    "                \"Информация о количестве договоров по инструментам, \"\n",
    "                \"являющимся производными финансовыми инструментами (по валютным парам)\",\n",
    "            ],\n",
    "            [\n",
    "                \"participants\",\n",
    "                \"Информация о количестве лиц, имеющих открытые позиции по инструментам, \"\n",
    "                \"являющимся производными финансовыми инструментами (по валютным парам)\",\n",
    "            ],\n",
    "            [\n",
    "                \"openpositions\",\n",
    "                \"Информация об открытых позициях по инструментам, являющимся производными \"\n",
    "                \"финансовыми инструментами (по валютным парам)\",\n",
    "            ],\n",
    "            [\n",
    "                \"expirationparticipants\",\n",
    "                \"Информация о количестве лиц, имеющих открытые позиции по договорам, \"\n",
    "                \"являющимся производными финансовыми инструментами (по срокам экспирации)\",\n",
    "            ],\n",
    "            [\n",
    "                \"expirationopenpositions\",\n",
    "                \"Информация об объеме открытых позиций по договорам, являющимся производными \"\n",
    "                \"финансовыми инструментами (по срокам экспирации)\",\n",
    "            ],\n",
    "        ],\n",
    "        columns=['report_name', 'decription']\n",
    "    )\n",
    "    report_names.set_index('report_name', inplace=True)\n",
    "    \n",
    "    sessions = pd.DataFrame(\n",
    "        data=[\n",
    "            [1, \"Основная сессия\"], [2, \"Вечерняя сессия\"], [3, \"Итого (все сессии)\"], [0, \"Утренняя сессия\"]\n",
    "        ], \n",
    "        columns=['sessions', 'decription']\n",
    "    )\n",
    "    sessions.set_index('sessions', inplace=True)\n",
    "    \n",
    "    \n",
    "    def __new__(cls, *args, **kwargs):\n",
    "        if not cls.__instance:                \n",
    "            cls.__instance = super().__new__(cls, *args, **kwargs)\n",
    "        return cls.__instance\n",
    "    \n",
    "    def __init__(self):\n",
    "        moex_dict = requests.get(self.globals_url).json()\n",
    "        for entity, columns in self.main_attribute.items():\n",
    "            setattr(self, entity, pd.DataFrame(\n",
    "                data=moex_dict[entity]['data'],\n",
    "                columns=moex_dict[entity]['columns'],\n",
    "                ).set_index(columns.main)\n",
    "            )\n",
    "        self.indexids = self.get_index_id()\n",
    "    \n",
    "    def get_index_id(self):\n",
    "        index_ids = requests.get(self.url_index_id).json()\n",
    "        df_index_ids = pd.DataFrame(\n",
    "            data=index_ids['indices']['data'], columns=index_ids['indices']['columns']\n",
    "        )\n",
    "        df_index_ids.set_index('indexid', inplace=True)\n",
    "        return df_index_ids\n",
    "    \n",
    "    \n",
    "    def description(self, entity: str, name):\n",
    "        entities = entity + \"s\"\n",
    "        use_entity = getattr(self, entities, None)\n",
    "        if use_entity is None:\n",
    "            raise NameError(f\"Entity '{entity}' is not found!\")\n",
    "        if not isinstance(use_entity, pd.DataFrame):\n",
    "            raise ValueError(f\"Entity '{entity}' hasn't description\")\n",
    "        return getattr(self, entity + \"s\").loc[name, (self.main_attribute[entities].description,)]\n",
    "            \n",
    "    \n",
    "GLOBAL_GUID = Globals()\n",
    "GLOBAL_GUID.markets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c65cc8e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Т+: А2-Акции и паи - безадрес.'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GLOBAL_GUID.description(\"board\", \"TQBS\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be8fb71f",
   "metadata": {},
   "source": [
    "# 4. Анализ сущностей"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "23363ca2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "duration\n",
      "securitytype\n",
      "securitycollection\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'asset': '❌',\n",
       " 'board': '✅',\n",
       " 'boardgroup': '✅',\n",
       " 'collection': '❌',\n",
       " 'datatype': '❌',\n",
       " 'engine': '✅',\n",
       " 'event_id': '❌',\n",
       " 'indexid': '❌',\n",
       " 'market': '✅',\n",
       " 'news_id': '❌',\n",
       " 'period': '❌',\n",
       " 'report_name': '❌',\n",
       " 'securities': '❌',\n",
       " 'security': '❌',\n",
       " 'securitygroup': '✅',\n",
       " 'session': '❌',\n",
       " 'ticker': '❌',\n",
       " 'year': '❌'}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for entity in Globals.main_attribute:\n",
    "    entity = entity[:-1]\n",
    "    if entity in CHECK_ENTITY:\n",
    "        CHECK_ENTITY[entity] = '✅'\n",
    "    else:\n",
    "        print(entity)\n",
    "CHECK_ENTITY"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9a4f99b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "ENTITY_DESCRIPTIONS[\"board\"] = \"Код торговой площадки (режим торгов)\"\n",
    "ENTITY_DESCRIPTIONS[\"boardgroup\"] = \"Группа торговых площадок\"\n",
    "ENTITY_DESCRIPTIONS[\"engine\"] = \"Признак рынка (фондовый, валютный, срочный...)\"\n",
    "ENTITY_DESCRIPTIONS[\"market\"] = \"Классфикация рынка: спот, индексы, рпс, репо, размещение, валюта и т.п.\"\n",
    "ENTITY_DESCRIPTIONS[\"securitygroup\"] = \"Класс финансового инструмента\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "eb2aeb49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/130', url_template='http://iss.moex.com/iss/securitygroups/{securitygroup}/collections/{collection}', description='Коллекция ценных бумаг входящие в группу'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/131', url_template='http://iss.moex.com/iss/securitygroups/{securitygroup}/collections/{collection}/securities', description='Описание инструментов')]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# collection\n",
    "[FINAL_DATA[inx] for inx in ENTITIES['collection']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "10d2313e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Сollections == securitycollections\n",
    "ENTITY_DESCRIPTIONS[\"collection\"] = (\n",
    "    \"Группировка финансовых инструментов по признакам (уровень, тип и тд). В словаре используется как securitycollection\"\n",
    ")\n",
    "CHECK_ENTITY[\"collection\"] = '✅'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "4655748f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/114', url_template='http://iss.moex.com/iss/archives/engines/{engine}/markets/{market}/{datatype}/years', description='Список годов, за которые существуют ссылки на файлы с архивом сделок и исторической биржевой информацией.\\rdatatype может принимать значения securities или trades.'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/116', url_template='http://iss.moex.com/iss/archives/engines/{engine}/markets/{market}/{datatype}/{period}', description='Получить список ccылок на годовые/месячные/дневные файлы с архивом сделок и исторической биржевой информацией.\\rdatatype может принимать значения securities или trades. \\rperiod может принимать значения yearly, monthly или daily.\\rПомесячные данные доступны только за последние 30 дней.'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/115', url_template='http://iss.moex.com/iss/archives/engines/{engine}/markets/{market}/{datatype}/years/{year}/months', description='Список месяцев в году, за которые существуют ссылки на файлы с архивом сделок и исторической биржевой информацией.\\rdatatype может принимать значения securities или trades.')]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# collection\n",
    "[FINAL_DATA[inx] for inx in ENTITIES['datatype']]  # datatype может принимать значения securities или trades."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "165da335",
   "metadata": {},
   "source": [
    "#### *Add dict of datatype directly in class Globals (above)*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "e8ef0f67",
   "metadata": {},
   "outputs": [],
   "source": [
    "ENTITY_DESCRIPTIONS[\"datatype\"] = \"securities or trades\"\n",
    "CHECK_ENTITY[\"datatype\"] = '✅'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7a285618",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/194', url_template='http://iss.moex.com/iss/events/{event_id}', description='Контент мероприятия биржи')]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# event_id\n",
    "[FINAL_DATA[inx] for inx in ENTITIES['event_id']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "98ac7414",
   "metadata": {},
   "outputs": [],
   "source": [
    "CHECK_ENTITY[\"event_id\"] = '✅'\n",
    "ENTITY_DESCRIPTIONS[\"event_id\"] = (\n",
    "    \"ID мероприятия проводимого Мосбиржей. Идут в порядке возрастания. Только ближайшие события \"\n",
    "    \"можно посмотреть на /iss/events\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "78ff4fd4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/147', url_template='http://iss.moex.com/iss/statistics/engines/stock/markets/index/analytics/{indexid}', description='Аналитические показатели за дату'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/148', url_template='http://iss.moex.com/iss/statistics/engines/stock/markets/index/analytics/{indexid}/tickers', description='Список тикеров за все время торгов'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/149', url_template='http://iss.moex.com/iss/statistics/engines/stock/markets/index/analytics/{indexid}/tickers/{ticker}', description='Информация по тикеру')]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# indexid\n",
    "[FINAL_DATA[inx] for inx in ENTITIES['indexid']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "37adc9d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>shortname</th>\n",
       "      <th>from</th>\n",
       "      <th>till</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>indexid</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>IMOEX</th>\n",
       "      <td>Индекс МосБиржи</td>\n",
       "      <td>2001-01-03</td>\n",
       "      <td>2023-05-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MOEX10</th>\n",
       "      <td>Индекс МосБиржи 10</td>\n",
       "      <td>2008-05-27</td>\n",
       "      <td>2023-05-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RTSI</th>\n",
       "      <td>Индекс РТС</td>\n",
       "      <td>2009-09-30</td>\n",
       "      <td>2023-05-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MOEXBC</th>\n",
       "      <td>Индекс голубых фишек</td>\n",
       "      <td>2010-01-14</td>\n",
       "      <td>2023-05-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MOEXBMI</th>\n",
       "      <td>Индекс широкого рынка</td>\n",
       "      <td>2011-12-30</td>\n",
       "      <td>2023-05-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RUEU10</th>\n",
       "      <td>MOEX Еврооблигации 10</td>\n",
       "      <td>2018-12-27</td>\n",
       "      <td>2021-10-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RUEUESG</th>\n",
       "      <td>RUEUESG</td>\n",
       "      <td>2021-03-21</td>\n",
       "      <td>2021-10-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RUEURAIF</th>\n",
       "      <td>Индекса МосБиржи еврооблигаций RUEURAIF</td>\n",
       "      <td>2020-06-01</td>\n",
       "      <td>2021-10-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RUMBICPL3</th>\n",
       "      <td>MBI CP L3</td>\n",
       "      <td>2011-01-11</td>\n",
       "      <td>2018-08-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RUMBITRL3</th>\n",
       "      <td>MBI TR L3</td>\n",
       "      <td>2011-01-11</td>\n",
       "      <td>2018-08-30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>219 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         shortname        from        till\n",
       "indexid                                                                   \n",
       "IMOEX                              Индекс МосБиржи  2001-01-03  2023-05-17\n",
       "MOEX10                          Индекс МосБиржи 10  2008-05-27  2023-05-17\n",
       "RTSI                                    Индекс РТС  2009-09-30  2023-05-17\n",
       "MOEXBC                        Индекс голубых фишек  2010-01-14  2023-05-17\n",
       "MOEXBMI                      Индекс широкого рынка  2011-12-30  2023-05-17\n",
       "...                                            ...         ...         ...\n",
       "RUEU10                       MOEX Еврооблигации 10  2018-12-27  2021-10-12\n",
       "RUEUESG                                    RUEUESG  2021-03-21  2021-10-12\n",
       "RUEURAIF   Индекса МосБиржи еврооблигаций RUEURAIF  2020-06-01  2021-10-12\n",
       "RUMBICPL3                                MBI CP L3  2011-01-11  2018-08-30\n",
       "RUMBITRL3                                MBI TR L3  2011-01-11  2018-08-30\n",
       "\n",
       "[219 rows x 3 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# def get_url_index():\n",
    "url_index_id = \"https://iss.moex.com/iss/statistics/engines/stock/markets/index/analytics.json\"\n",
    "index_ids = requests.get(url_index_id).json()\n",
    "df_index_ids = pd.DataFrame(\n",
    "    data=index_ids['indices']['data'], columns=index_ids['indices']['columns']\n",
    ")\n",
    "df_index_ids.set_index('indexid', inplace=True)\n",
    "df_index_ids"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ede1b53e",
   "metadata": {},
   "source": [
    "#### Add dict of indexid directly in class Globals (above)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "73082304",
   "metadata": {},
   "outputs": [],
   "source": [
    "CHECK_ENTITY[\"indexid\"] = '✅'\n",
    "ENTITY_DESCRIPTIONS[\"indexid\"] = \"Код индекса (бенчмарка) публикуемого и/или расчитываемого Мосбиржей\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "9eb63d85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/192', url_template='http://iss.moex.com/iss/sitenews/{news_id}', description='Новость сайта')]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# news_id\n",
    "[FINAL_DATA[inx] for inx in ENTITIES['news_id']] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "6ed98fff",
   "metadata": {},
   "outputs": [],
   "source": [
    "CHECK_ENTITY[\"news_id\"] = '✅'\n",
    "ENTITY_DESCRIPTIONS[\"news_id\"] = \"Код новостной рассылки Мосбиржи. Реестр новостей можно увидить на /iss/sitenews\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "768688fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/116', url_template='http://iss.moex.com/iss/archives/engines/{engine}/markets/{market}/{datatype}/{period}', description='Получить список ccылок на годовые/месячные/дневные файлы с архивом сделок и исторической биржевой информацией.\\rdatatype может принимать значения securities или trades. \\rperiod может принимать значения yearly, monthly или daily.\\rПомесячные данные доступны только за последние 30 дней.')]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# period\n",
    "[FINAL_DATA[inx] for inx in ENTITIES['period']] # period может принимать значения yearly, monthly или daily"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "dd9a0499",
   "metadata": {},
   "outputs": [],
   "source": [
    "CHECK_ENTITY[\"period\"] = '✅'\n",
    "ENTITY_DESCRIPTIONS[\"period\"] = \"yearly, monthly или daily\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "499249e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/219', url_template='http://iss.moex.com/iss/statistics/engines/{engine}/derivatives/{report_name}', description='Еженедельные отчеты по валютным деривативам:\\r\\rnumtrades - Информация о количестве договоров по инструментам, являющимся производными финансовыми инструментами (по валютным парам)\\rparticipants - Информация о количестве лиц, имеющих открытые позиции по инструментам, являющимся производными финансовыми инструментами (по валютным парам)\\ropenpositions - Информация об открытых позициях по инструментам, являющимся производными финансовыми инструментами (по валютным парам)\\rexpirationparticipants - Информация о количестве лиц, имеющих открытые позиции по договорам, являющимся производными финансовыми инструментами (по срокам экспирации)\\rexpirationopenpositions - Информация об объеме открытых позиций по договорам, являющимся производными финансовыми инструментами (по срокам экспирации)'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/220', url_template='http://iss.moex.com/iss/statistics/engines/{engine}/monthly/{report_name}', description='')]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# report_name\n",
    "[FINAL_DATA[inx] for inx in ENTITIES['report_name']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "86403bcf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_name</th>\n",
       "      <th>decription</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>numtrades</td>\n",
       "      <td>Информация о количестве договоров по инструмен...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>participants</td>\n",
       "      <td>Информация о количестве лиц, имеющих открытые ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>openpositions</td>\n",
       "      <td>Информация об открытых позициях по инструмента...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>expirationparticipants</td>\n",
       "      <td>Информация о количестве лиц, имеющих открытые ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>expirationopenpositions</td>\n",
       "      <td>Информация об объеме открытых позиций по догов...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               report_name                                         decription\n",
       "0                numtrades  Информация о количестве договоров по инструмен...\n",
       "1             participants  Информация о количестве лиц, имеющих открытые ...\n",
       "2            openpositions  Информация об открытых позициях по инструмента...\n",
       "3   expirationparticipants  Информация о количестве лиц, имеющих открытые ...\n",
       "4  expirationopenpositions  Информация об объеме открытых позиций по догов..."
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_desc_reportname = [\n",
    "    [\n",
    "        \"numtrades\", \n",
    "        \"Информация о количестве договоров по инструментам, \"\n",
    "        \"являющимся производными финансовыми инструментами (по валютным парам)\",\n",
    "    ],\n",
    "    [\n",
    "        \"participants\",\n",
    "        \"Информация о количестве лиц, имеющих открытые позиции по инструментам, \"\n",
    "        \"являющимся производными финансовыми инструментами (по валютным парам)\",\n",
    "    ],\n",
    "    [\n",
    "        \"openpositions\",\n",
    "        \"Информация об открытых позициях по инструментам, являющимся производными \"\n",
    "        \"финансовыми инструментами (по валютным парам)\",\n",
    "    ],\n",
    "    [\n",
    "        \"expirationparticipants\",\n",
    "        \"Информация о количестве лиц, имеющих открытые позиции по договорам, \"\n",
    "        \"являющимся производными финансовыми инструментами (по срокам экспирации)\",\n",
    "    ],\n",
    "    [\n",
    "        \"expirationopenpositions\",\n",
    "        \"Информация об объеме открытых позиций по договорам, являющимся производными \"\n",
    "        \"финансовыми инструментами (по срокам экспирации)\",\n",
    "    ],\n",
    "]\n",
    "df_report_name = pd.DataFrame(data=data_desc_reportname, columns=['report_name', 'decription'])\n",
    "df_report_name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4712cbb",
   "metadata": {},
   "source": [
    "#### *Add data of report_name directly in class Globals (above)*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "632bb046",
   "metadata": {},
   "outputs": [],
   "source": [
    "CHECK_ENTITY[\"report_name\"] = '✅'\n",
    "ENTITY_DESCRIPTIONS[\"report_name\"] = (\n",
    "    \"Еженедельные отчеты по ВАЛЮТНЫМ (! только !) деривативам. По первичному анализу - OTC / c ЦК и нестандартные ПФИ. Нужны детали.\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "0e12c010",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/789', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/.*?{securities}/columns', description='Получить описание полей для запросов исторических данных по бумагам для рынка.')]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[FINAL_DATA[inx] for inx in ENTITIES['securities']]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28f7b7af",
   "metadata": {},
   "source": [
    "Данный поинт возращает тоже, что и /iss/engines/[engine]/markets/[market]/.*?securities/columns\n",
    "\n",
    "\n",
    "Обращение к /iss/engines/[engine]/markets/[market]/securities/columns вернет описание исторических данных. Адрес выше можно исключить из доступных апи (хотя в истории поля могли меняться)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "37bcd6b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'❌'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CHECK_ENTITY.pop(\"securities\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "4599f44d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/13', url_template='http://iss.moex.com/iss/securities/{security}', description='Получить спецификацию инструмента. Например: https://iss.moex.com/iss/securities/IMOEX.xml'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/160', url_template='http://iss.moex.com/iss/securities/{security}/indices', description='Список индексов в которые входит бумага'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/214', url_template='http://iss.moex.com/iss/securities/{security}/aggregates', description='Агрегированные итоги торгов за дату по рынкам'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/817', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/sessions/{session}/securities/{security}', description='Получить историю по одной бумаге на рынке за интервал дат.'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/819', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/sessions/{session}/boardgroups/{boardgroup}/securities/{security}', description='Получить историю торгов для указанной бумаги на выбранной группе режимов торгов за указанный интервал дат.'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/815', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/sessions/{session}/boards/{board}/securities/{security}', description='Получить историю торгов для указанной бумаги на указанном режиме торгов за указанный интервал дат.'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/52', url_template='http://iss.moex.com/iss/engines/{engine}/markets/{market}/securities/{security}', description='Получить данные по конкретному инструменту рынка.Например: https://iss.moex.com/iss/engines/stock/markets/shares/securities/AFLT.xml'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/55', url_template='http://iss.moex.com/iss/engines/{engine}/markets/{market}/securities/{security}/trades', description='Получить сделки по инструменту. Например: https://iss.moex.com/iss/engines/stock/markets/shares/securities/AFLT/trades.xml'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/54', url_template='http://iss.moex.com/iss/engines/{engine}/markets/{market}/securities/{security}/orderbook', description='Получить стакан заявок по инструменту.Например: https://iss.moex.com/iss/engines/stock/markets/shares/securities/AFLT/orderbook.xml'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/53', url_template='http://iss.moex.com/iss/engines/{engine}/markets/{market}/boards/{board}/securities/{security}', description='Получить данные по указанному инструменту на выбранном режиме торгов.')]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[FINAL_DATA[inx] for inx in ENTITIES['security']][:10]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ce48053",
   "metadata": {},
   "source": [
    "Под security используется secid ФИ на Мосбирже. Получение торгуемых инструментов в разрезе торгуемости, площадок, а также их описание - отдельная задача, которую решим позже. Сейчас отметим сущность как прочеканную."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "c855d889",
   "metadata": {},
   "outputs": [],
   "source": [
    "CHECK_ENTITY[\"security\"] = '✅'\n",
    "ENTITY_DESCRIPTIONS[\"security\"] = \"Secid финансового инструмента\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "a817cecc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/813', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/sessions/{session}/securities', description='Получить историю по всем бумагам на рынке за одну дату.Например: https://iss.moex.com/iss/history/engines/stock/markets/index/securities.xml?date=2010-11-22'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/817', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/sessions/{session}/securities/{security}', description='Получить историю по одной бумаге на рынке за интервал дат.'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/825', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/session/{session}/boardgroups/{boardgroup}/securities', description='Получить историю торгов для всех бумаг на указанной группе режимов торгов за указанную дату.'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/819', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/sessions/{session}/boardgroups/{boardgroup}/securities/{security}', description='Получить историю торгов для указанной бумаги на выбранной группе режимов торгов за указанный интервал дат.'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/821', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/sessions/{session}/boards/{board}/securities', description='Получить историю торгов для всех бумаг на указанном режиме торгов отфильтрованных по дате.'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/815', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/sessions/{session}/boards/{board}/securities/{security}', description='Получить историю торгов для указанной бумаги на указанном режиме торгов за указанный интервал дат.')]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[FINAL_DATA[inx] for inx in ENTITIES['session']]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19da4c21",
   "metadata": {},
   "source": [
    "Cессии:\n",
    "- 0 - Утренняя\n",
    "- 1 - Основная\n",
    "- 2 - Вечерняя\n",
    "- 3 - Итого"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "95eb76c5",
   "metadata": {},
   "source": [
    "#### Add dict of session directly in class Globals (above)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "87658b88",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>decription</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sessions</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Основная сессия</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Вечерняя сессия</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Итого (все сессии)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Утренняя сессия</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  decription\n",
       "sessions                    \n",
       "1            Основная сессия\n",
       "2            Вечерняя сессия\n",
       "3         Итого (все сессии)\n",
       "0            Утренняя сессия"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CHECK_ENTITY[\"session\"] = '✅'\n",
    "ENTITY_DESCRIPTIONS[\"session\"] = \"Сессия торгов (утро, вечер, основная, итого)\"\n",
    "GLOBAL_GUID.sessions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "fde055d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/149', url_template='http://iss.moex.com/iss/statistics/engines/stock/markets/index/analytics/{indexid}/tickers/{ticker}', description='Информация по тикеру')]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[FINAL_DATA[inx] for inx in ENTITIES['ticker']]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6cd1c48f",
   "metadata": {},
   "source": [
    "Не получилось добыть данные. \n",
    "\n",
    "/iss/statistics/engines/stock/markets/index/analytics/[indexid]/tickers возвращает список тикеров формирующих индекс ([indexid]). Но добавление тикера в запрос возвращает пустой результат. Возможно работает с ограниченным числом индексов \n",
    "или поинт доступен только для платных подписчиков.\n",
    "По полям - капитализация эмитента, вляиние бумаги на индекс и прочие статистические показатели.\n",
    "Также ticker это secid ФИ или сущность - security.\n",
    "\n",
    "Проставим как прочеканную."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "2c999847",
   "metadata": {},
   "outputs": [],
   "source": [
    "ENTITY_DESCRIPTIONS[\"ticker\"] = \"Тикер бумаги в индексе долевых ФИ. По сути - Secid. Детали: /iss/statistics/engines/stock/markets/index/analytics/[indexid]/tickers\"\n",
    "CHECK_ENTITY[\"ticker\"] = '✅'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "94c403ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/115', url_template='http://iss.moex.com/iss/archives/engines/{engine}/markets/{market}/{datatype}/years/{year}/months', description='Список месяцев в году, за которые существуют ссылки на файлы с архивом сделок и исторической биржевой информацией.\\rdatatype может принимать значения securities или trades.')]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[FINAL_DATA[inx] for inx in ENTITIES['year']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "4cfb1923",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Год - просто год:)\n",
    "ENTITY_DESCRIPTIONS[\"year\"] = \"Год, только для архивов\"\n",
    "CHECK_ENTITY[\"year\"] = '✅'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "fd65b67e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[MoexApi(url_faq='http://iss.moex.com/iss/reference/877', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/options/assets/{asset}', description='Опционные серии'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/879', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/options/assets/{asset}/volumes', description='Объем торгов для опционной серии'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/881', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/options/assets/{asset}/optionboard', description='Доска опционов'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/883', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/options/assets/{asset}/openpositions', description='Открытые позиции по опционной серии'),\n",
       " MoexApi(url_faq='http://iss.moex.com/iss/reference/885', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/options/assets/{asset}/turnovers', description='Объем торгов для опционной серии')]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# asset\n",
    "[FINAL_DATA[inx] for inx in ENTITIES['asset']]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c577f22",
   "metadata": {},
   "source": [
    "По /iss/securitygroups/[securitygroup]/collections/[collection]/securities можно получить описание опцинов. Полученные поля содержат **ASSETCODE** - secid базового ФИ. Поэтому поле asset считаем прочеканым."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "86862235",
   "metadata": {},
   "outputs": [],
   "source": [
    "ENTITY_DESCRIPTIONS[\"asset\"] = \"Secid базового актива для опционов.\"\n",
    "CHECK_ENTITY[\"asset\"] = '✅'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "a42e73af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'asset': '✅',\n",
       " 'board': '✅',\n",
       " 'boardgroup': '✅',\n",
       " 'collection': '✅',\n",
       " 'datatype': '✅',\n",
       " 'engine': '✅',\n",
       " 'event_id': '✅',\n",
       " 'indexid': '✅',\n",
       " 'market': '✅',\n",
       " 'news_id': '✅',\n",
       " 'period': '✅',\n",
       " 'report_name': '✅',\n",
       " 'security': '✅',\n",
       " 'securitygroup': '✅',\n",
       " 'session': '✅',\n",
       " 'ticker': '✅',\n",
       " 'year': '✅'}"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CHECK_ENTITY"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "a3c8a976",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'asset': 'Secid базового актива для опционов.',\n",
       " 'board': 'Код торговой площадки (режим торгов)',\n",
       " 'boardgroup': 'Группа торговых площадок',\n",
       " 'engine': 'Признак рынка (фондовый, валютный, срочный...)',\n",
       " 'market': 'Классфикация рынка: спот, индексы, рпс, репо, размещение, валюта и т.п.',\n",
       " 'securitygroup': 'Класс финансового инструмента',\n",
       " 'collection': 'Группировка финансовых инструментов по признакам (уровень, тип и тд). В словаре используется как securitycollection',\n",
       " 'datatype': 'securities or trades',\n",
       " 'event_id': 'ID мероприятия проводимого Мосбиржей. Идут в порядке возрастания. Только ближайшие события можно посмотреть на /iss/events',\n",
       " 'indexid': 'Код индекса (бенчмарка) публикуемого и/или расчитываемого Мосбиржей',\n",
       " 'news_id': 'Код новостной рассылки Мосбиржи. Реестр новостей можно увидить на /iss/sitenews',\n",
       " 'period': 'yearly, monthly или daily',\n",
       " 'report_name': 'Еженедельные отчеты по ВАЛЮТНЫМ (! только !) деривативам. По первичному анализу - OTC / c ЦК и нестандартные ПФИ. Нужны детали.',\n",
       " 'security': 'Secid финансового инструмента',\n",
       " 'session': 'Сессия торгов (утро, вечер, основная, итого)',\n",
       " 'ticker': 'Тикер бумаги в индексе долевых ФИ. По сути - Secid. Детали: /iss/statistics/engines/stock/markets/index/analytics/[indexid]/tickers',\n",
       " 'year': 'Год, только для архивов'}"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ENTITY_DESCRIPTIONS"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0036f8b",
   "metadata": {},
   "source": [
    "# 5. Доступность endpoint'ов\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2f0ef63",
   "metadata": {},
   "source": [
    "Так как некоторые эндпоинты ответственны за определенный тип ФИ, рынка, площадки и тд, создадим несколько базовых словарей, данные которых будут подставляться в url при получении пустых ответов.\n",
    "В будущем, можно решить задачу связи сущностей друг с другом."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "ad4d9e2b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'engine': 'stock'},\n",
       " {'engine': 'currency'},\n",
       " {'engine': 'futures'},\n",
       " {'engine': 'state'},\n",
       " {'engine': 'commodity'},\n",
       " {'engine': 'interventions'},\n",
       " {'engine': 'offboard'},\n",
       " {'engine': 'agro'},\n",
       " {'engine': 'otc'}]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Начнем с сущностей:\n",
    "url_params = [{\"engine\": engine} for engine in GLOBAL_GUID.engines.index]\n",
    "state = url_params.pop(1)\n",
    "url_params.insert(3, state)\n",
    "url_params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "f07f5f2f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'engine': 'stock', 'market': 'shares'},\n",
       " {'engine': 'currency', 'market': 'selt'},\n",
       " {'engine': 'futures', 'market': 'forts'},\n",
       " {'engine': 'state', 'market': 'bonds'},\n",
       " {'engine': 'commodity', 'market': 'futures'},\n",
       " {'engine': 'interventions', 'market': 'grain'},\n",
       " {'engine': 'offboard', 'market': 'bonds'},\n",
       " {'engine': 'agro', 'market': 'sugar'},\n",
       " {'engine': 'otc', 'market': 'bonds'}]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Добавим первичные рынки по каждой сущности (есть маркетплайс и есть книга заявок)\n",
    "for dict_ in url_params:\n",
    "    engine = dict_['engine']\n",
    "    market_slice = GLOBAL_GUID.markets.query('trade_engine_name==@engine')\n",
    "    if market_slice.shape[0] == 1:\n",
    "        dict_['market'] = market_slice.iloc[0].name\n",
    "    else:\n",
    "        market_slice_tmp = market_slice.query(\"marketplace.notnull()\")\n",
    "        if market_slice_tmp.shape[0]:\n",
    "            dict_['market'] = market_slice_tmp.sort_values(by=['id']).iloc[0].name\n",
    "        else:\n",
    "            dict_['market'] = market_slice.query(\"has_orderbook==1\").sort_values(by=['id']).iloc[0].name\n",
    "url_params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "a078e8bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'engine': 'stock', 'market': 'shares', 'boardgroup': 'stock_shares_tplus'},\n",
       " {'engine': 'currency', 'market': 'selt', 'boardgroup': 'currency'},\n",
       " {'engine': 'futures', 'market': 'forts', 'boardgroup': 'futures_forts'},\n",
       " {'engine': 'state', 'market': 'bonds', 'boardgroup': 'state'},\n",
       " {'engine': 'commodity',\n",
       "  'market': 'futures',\n",
       "  'boardgroup': 'commodity_futures'},\n",
       " {'engine': 'interventions',\n",
       "  'market': 'grain',\n",
       "  'boardgroup': 'interventions_grain'},\n",
       " {'engine': 'offboard', 'market': 'bonds', 'boardgroup': 'offboard_bond_all'},\n",
       " {'engine': 'agro', 'market': 'sugar', 'boardgroup': 'agro_sugar_all'},\n",
       " {'engine': 'otc', 'market': 'bonds', 'boardgroup': 'otc_bonds_tplus'}]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Добавим первичную группу площадок по каждой сущности\n",
    "for dict_ in url_params:\n",
    "    engine, market = dict_['engine'], dict_['market']\n",
    "    dict_['boardgroup'] = GLOBAL_GUID.boardgroups.query(\n",
    "        'market_name==@market and trade_engine_name==@engine and is_default==1'\n",
    "    ).sort_values(by=['id']).iloc[0].name\n",
    "url_params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "8b09d699",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'engine': 'stock',\n",
       "  'market': 'shares',\n",
       "  'boardgroup': 'stock_shares_tplus',\n",
       "  'board': 'TQBR'},\n",
       " {'engine': 'currency',\n",
       "  'market': 'selt',\n",
       "  'boardgroup': 'currency',\n",
       "  'board': 'CETS'},\n",
       " {'engine': 'futures',\n",
       "  'market': 'forts',\n",
       "  'boardgroup': 'futures_forts',\n",
       "  'board': 'RFUD'},\n",
       " {'engine': 'state',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'state',\n",
       "  'board': 'MAIN'},\n",
       " {'engine': 'commodity',\n",
       "  'market': 'futures',\n",
       "  'boardgroup': 'commodity_futures',\n",
       "  'board': 'FOCM'},\n",
       " {'engine': 'interventions',\n",
       "  'market': 'grain',\n",
       "  'boardgroup': 'interventions_grain',\n",
       "  'board': 'GSEL'},\n",
       " {'engine': 'offboard',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'offboard_bond_all',\n",
       "  'board': 'OBBO'},\n",
       " {'engine': 'agro',\n",
       "  'market': 'sugar',\n",
       "  'boardgroup': 'agro_sugar_all',\n",
       "  'board': 'SUGR'},\n",
       " {'engine': 'otc',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'otc_bonds_tplus',\n",
       "  'board': 'OCTR'}]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Добавим площадку\n",
    "for dict_ in url_params:\n",
    "    engine_id = GLOBAL_GUID.engines.loc[dict_['engine']].id\n",
    "    slice_market_df = GLOBAL_GUID.markets.loc[dict_['market']]\n",
    "    if isinstance(slice_market_df, pd.DataFrame):\n",
    "        market_id = slice_market_df.query(\"trade_engine_id==@engine_id\").iloc[0].market_id\n",
    "    else:\n",
    "        market_id = slice_market_df.market_id\n",
    "    board_group_id = GLOBAL_GUID.boardgroups.loc[dict_[\"boardgroup\"]].id\n",
    "\n",
    "    dict_['board'] = GLOBAL_GUID.boards.query(\n",
    "    \"board_group_id==@board_group_id and engine_id==@engine_id and market_id==@market_id \"\n",
    "    \" and is_primary==1\"\n",
    "    ).sort_values(by=['id']).iloc[0].name\n",
    "    \n",
    "url_params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "7e926708",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>board_group_id</th>\n",
       "      <th>engine_id</th>\n",
       "      <th>market_id</th>\n",
       "      <th>board_title</th>\n",
       "      <th>is_traded</th>\n",
       "      <th>has_candles</th>\n",
       "      <th>is_primary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>boardid</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>TQBR</th>\n",
       "      <td>129</td>\n",
       "      <td>57</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Т+: Акции и ДР - безадрес.</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CETS</th>\n",
       "      <td>21</td>\n",
       "      <td>13</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>Системные сделки - безадрес.</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RFUD</th>\n",
       "      <td>101</td>\n",
       "      <td>45</td>\n",
       "      <td>4</td>\n",
       "      <td>22</td>\n",
       "      <td>Фьючерсы</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MAIN</th>\n",
       "      <td>19</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>ГЦБ</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FOCM</th>\n",
       "      <td>80</td>\n",
       "      <td>20</td>\n",
       "      <td>5</td>\n",
       "      <td>18</td>\n",
       "      <td>Фьючерсы на товарные активы</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GSEL</th>\n",
       "      <td>94</td>\n",
       "      <td>24</td>\n",
       "      <td>6</td>\n",
       "      <td>20</td>\n",
       "      <td>Интервенции по продаже зерна</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OBBO</th>\n",
       "      <td>297</td>\n",
       "      <td>141</td>\n",
       "      <td>7</td>\n",
       "      <td>39</td>\n",
       "      <td>ОТС-система: облигации</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SUGR</th>\n",
       "      <td>427</td>\n",
       "      <td>271</td>\n",
       "      <td>9</td>\n",
       "      <td>51</td>\n",
       "      <td>Агро: Сахар</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OCTR</th>\n",
       "      <td>1022</td>\n",
       "      <td>1021</td>\n",
       "      <td>1012</td>\n",
       "      <td>1013</td>\n",
       "      <td>ОТС: Облигации Т+ - безадресные</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           id  board_group_id  engine_id  market_id  \\\n",
       "boardid                                               \n",
       "TQBR      129              57          1          1   \n",
       "CETS       21              13          3         10   \n",
       "RFUD      101              45          4         22   \n",
       "MAIN       19              10          2          6   \n",
       "FOCM       80              20          5         18   \n",
       "GSEL       94              24          6         20   \n",
       "OBBO      297             141          7         39   \n",
       "SUGR      427             271          9         51   \n",
       "OCTR     1022            1021       1012       1013   \n",
       "\n",
       "                             board_title  is_traded  has_candles  is_primary  \n",
       "boardid                                                                       \n",
       "TQBR          Т+: Акции и ДР - безадрес.          1            1           1  \n",
       "CETS        Системные сделки - безадрес.          1            1           1  \n",
       "RFUD                            Фьючерсы          1            1           1  \n",
       "MAIN                                 ГЦБ          0            1           1  \n",
       "FOCM         Фьючерсы на товарные активы          0            1           1  \n",
       "GSEL        Интервенции по продаже зерна          1            0           1  \n",
       "OBBO              ОТС-система: облигации          0            1           1  \n",
       "SUGR                         Агро: Сахар          1            1           1  \n",
       "OCTR     ОТС: Облигации Т+ - безадресные          1            1           1  "
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GLOBAL_GUID.boards.loc[[x[\"board\"] for x in url_params]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "b112246b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>is_hidden</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>stock_index</th>\n",
       "      <td>12</td>\n",
       "      <td>Индексы</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_shares</th>\n",
       "      <td>4</td>\n",
       "      <td>Акции</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds</th>\n",
       "      <td>3</td>\n",
       "      <td>Облигации</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt</th>\n",
       "      <td>9</td>\n",
       "      <td>Валюта</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures_forts</th>\n",
       "      <td>10</td>\n",
       "      <td>Фьючерсы</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures_options</th>\n",
       "      <td>26</td>\n",
       "      <td>Опционы</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_dr</th>\n",
       "      <td>18</td>\n",
       "      <td>Депозитарные расписки</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_foreign_shares</th>\n",
       "      <td>33</td>\n",
       "      <td>Иностранные ц.б.</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_eurobond</th>\n",
       "      <td>6</td>\n",
       "      <td>Еврооблигации</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_ppif</th>\n",
       "      <td>5</td>\n",
       "      <td>Паи ПИФов</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_etf</th>\n",
       "      <td>20</td>\n",
       "      <td>Биржевые фонды</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_metal</th>\n",
       "      <td>24</td>\n",
       "      <td>Драгоценные металлы</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_qnv</th>\n",
       "      <td>21</td>\n",
       "      <td>Квал. инвесторы</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_gcc</th>\n",
       "      <td>27</td>\n",
       "      <td>Клиринговые сертификаты участия</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_deposit</th>\n",
       "      <td>29</td>\n",
       "      <td>Депозиты с ЦК</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_futures</th>\n",
       "      <td>28</td>\n",
       "      <td>Валютный фьючерс</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_indices</th>\n",
       "      <td>31</td>\n",
       "      <td>Валютные фиксинги</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_mortgage</th>\n",
       "      <td>22</td>\n",
       "      <td>Ипотечный сертификат</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      id                            title  is_hidden\n",
       "name                                                                \n",
       "stock_index           12                          Индексы          0\n",
       "stock_shares           4                            Акции          0\n",
       "stock_bonds            3                        Облигации          0\n",
       "currency_selt          9                           Валюта          0\n",
       "futures_forts         10                         Фьючерсы          0\n",
       "futures_options       26                          Опционы          0\n",
       "stock_dr              18            Депозитарные расписки          0\n",
       "stock_foreign_shares  33                 Иностранные ц.б.          0\n",
       "stock_eurobond         6                    Еврооблигации          0\n",
       "stock_ppif             5                        Паи ПИФов          0\n",
       "stock_etf             20                   Биржевые фонды          0\n",
       "currency_metal        24              Драгоценные металлы          0\n",
       "stock_qnv             21                  Квал. инвесторы          0\n",
       "stock_gcc             27  Клиринговые сертификаты участия          0\n",
       "stock_deposit         29                    Депозиты с ЦК          0\n",
       "currency_futures      28                 Валютный фьючерс          0\n",
       "currency_indices      31                Валютные фиксинги          0\n",
       "stock_mortgage        22             Ипотечный сертификат          1"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GLOBAL_GUID.securitygroups"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "9ad7ac2f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'engine': 'stock',\n",
       "  'market': 'shares',\n",
       "  'boardgroup': 'stock_shares_tplus',\n",
       "  'board': 'TQBR',\n",
       "  'securitygroup': 'stock_shares'},\n",
       " {'engine': 'currency',\n",
       "  'market': 'selt',\n",
       "  'boardgroup': 'currency',\n",
       "  'board': 'CETS',\n",
       "  'securitygroup': 'currency_selt'},\n",
       " {'engine': 'futures',\n",
       "  'market': 'forts',\n",
       "  'boardgroup': 'futures_forts',\n",
       "  'board': 'RFUD',\n",
       "  'securitygroup': 'futures_forts'},\n",
       " {'engine': 'state',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'state',\n",
       "  'board': 'MAIN',\n",
       "  'securitygroup': 'stock_bonds'},\n",
       " {'engine': 'commodity',\n",
       "  'market': 'futures',\n",
       "  'boardgroup': 'commodity_futures',\n",
       "  'board': 'FOCM',\n",
       "  'securitygroup': 'futures_forts'},\n",
       " {'engine': 'interventions',\n",
       "  'market': 'grain',\n",
       "  'boardgroup': 'interventions_grain',\n",
       "  'board': 'GSEL'},\n",
       " {'engine': 'offboard',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'offboard_bond_all',\n",
       "  'board': 'OBBO',\n",
       "  'securitygroup': 'stock_bonds'},\n",
       " {'engine': 'agro',\n",
       "  'market': 'sugar',\n",
       "  'boardgroup': 'agro_sugar_all',\n",
       "  'board': 'SUGR'},\n",
       " {'engine': 'otc',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'otc_bonds_tplus',\n",
       "  'board': 'OCTR',\n",
       "  'securitygroup': 'stock_bonds'}]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Добавим securitygroup (ручками)\n",
    "group_entity = {\n",
    "    \"stock\": \"stock_shares\",\n",
    "    \"currency\": \"currency_selt\",\n",
    "    \"futures\": \"futures_forts\",\n",
    "    \"state\": \"stock_bonds\",\n",
    "    \"commodity\": \"futures_forts\",\n",
    "    \"offboard\": \"stock_bonds\",\n",
    "    \"otc\": \"stock_bonds\",\n",
    "}\n",
    "for d in url_params:\n",
    "    if d['engine'] in group_entity:\n",
    "        d['securitygroup'] = group_entity[d['engine']]\n",
    "url_params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "bb13d59c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "id               4\n",
       "title        Акции\n",
       "is_hidden        0\n",
       "Name: stock_shares, dtype: object"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GLOBAL_GUID.securitygroups.loc['stock_shares']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "acbb4161",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>is_hidden</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>currency_selt</th>\n",
       "      <td>9</td>\n",
       "      <td>Валюта</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds</th>\n",
       "      <td>3</td>\n",
       "      <td>Облигации</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_shares</th>\n",
       "      <td>4</td>\n",
       "      <td>Акции</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures_forts</th>\n",
       "      <td>10</td>\n",
       "      <td>Фьючерсы</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               id      title  is_hidden\n",
       "name                                   \n",
       "currency_selt   9     Валюта          0\n",
       "stock_bonds     3  Облигации          0\n",
       "stock_shares    4      Акции          0\n",
       "futures_forts  10   Фьючерсы          0"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>security_group_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>stock_shares_all</th>\n",
       "      <td>3</td>\n",
       "      <td>Все акции</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_all</th>\n",
       "      <td>7</td>\n",
       "      <td>Все</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_shares_one</th>\n",
       "      <td>160</td>\n",
       "      <td>Уровень 1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_shares_two</th>\n",
       "      <td>161</td>\n",
       "      <td>Уровень 2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_shares_three</th>\n",
       "      <td>162</td>\n",
       "      <td>Уровень 3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_one</th>\n",
       "      <td>163</td>\n",
       "      <td>Все уровень 1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_two</th>\n",
       "      <td>164</td>\n",
       "      <td>Все уровень 2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_three</th>\n",
       "      <td>165</td>\n",
       "      <td>Все уровень 3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_all_swap</th>\n",
       "      <td>170</td>\n",
       "      <td>Все валюты СВОП</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_other_spot</th>\n",
       "      <td>171</td>\n",
       "      <td>Другие валюты СПОТ</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_eur_spot</th>\n",
       "      <td>172</td>\n",
       "      <td>EUR/RUB СПОТ</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_usd_spot</th>\n",
       "      <td>173</td>\n",
       "      <td>USD/RUB СПОТ</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_usd_swap</th>\n",
       "      <td>174</td>\n",
       "      <td>USD/RUB СВОП</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_other_swap</th>\n",
       "      <td>175</td>\n",
       "      <td>Другие валюты СВОП</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_cny_swap</th>\n",
       "      <td>176</td>\n",
       "      <td>CNY/RUB СВОП</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_all_spot</th>\n",
       "      <td>177</td>\n",
       "      <td>Все валюты СПОТ</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_eurusd_spot</th>\n",
       "      <td>178</td>\n",
       "      <td>EUR/USD СПОТ</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_eur_swap</th>\n",
       "      <td>179</td>\n",
       "      <td>EUR/RUB СВОП</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_eurusd_swap</th>\n",
       "      <td>180</td>\n",
       "      <td>EUR/USD СВОП</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>currency_selt_cny_spot</th>\n",
       "      <td>181</td>\n",
       "      <td>CNY/RUB СПОТ</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_exchange_corp_one</th>\n",
       "      <td>185</td>\n",
       "      <td>Биржевые уровень 1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_ofz_all</th>\n",
       "      <td>186</td>\n",
       "      <td>Все ОФЗ</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_ifi_two</th>\n",
       "      <td>187</td>\n",
       "      <td>Иностранных эмитентов уровень 2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_corp_three</th>\n",
       "      <td>188</td>\n",
       "      <td>Корпоративные уровень 3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_corp_all</th>\n",
       "      <td>189</td>\n",
       "      <td>Все корпоративные</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_exchange_three</th>\n",
       "      <td>190</td>\n",
       "      <td>Биржевые уровень 3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_municipal_two</th>\n",
       "      <td>191</td>\n",
       "      <td>Муниципальные уровень 2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_subfederal_three</th>\n",
       "      <td>192</td>\n",
       "      <td>Субъектов РФ уровень 3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_cb_all</th>\n",
       "      <td>193</td>\n",
       "      <td>Все Банка России</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_corp_two</th>\n",
       "      <td>194</td>\n",
       "      <td>Корпоративные уровень 2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_exchange_two</th>\n",
       "      <td>195</td>\n",
       "      <td>Биржевые уровень 2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_ifi_three</th>\n",
       "      <td>196</td>\n",
       "      <td>Иностранных эмитентов уровень 3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_ifi_all</th>\n",
       "      <td>197</td>\n",
       "      <td>Все иностранных эмитентов</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_subfederal_all</th>\n",
       "      <td>198</td>\n",
       "      <td>Все субъектов РФ</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_ifi_one</th>\n",
       "      <td>199</td>\n",
       "      <td>Иностранных эмитентов уровень 1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_exchange_all</th>\n",
       "      <td>200</td>\n",
       "      <td>Все биржевые</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_municipal_one</th>\n",
       "      <td>201</td>\n",
       "      <td>Муниципальные уровень 1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_corp_one</th>\n",
       "      <td>202</td>\n",
       "      <td>Корпоративные уровень 1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_municipal_three</th>\n",
       "      <td>203</td>\n",
       "      <td>Муниципальные уровень 3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_subfederal_two</th>\n",
       "      <td>204</td>\n",
       "      <td>Субъектов РФ уровень 2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_municipal_all</th>\n",
       "      <td>205</td>\n",
       "      <td>Все муниципальные</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stock_bonds_subfederal_one</th>\n",
       "      <td>206</td>\n",
       "      <td>Субъектов РФ уровень 1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures_forts_commodity</th>\n",
       "      <td>223</td>\n",
       "      <td>Фьючерсы на товарные контракты</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures_forts_shares</th>\n",
       "      <td>224</td>\n",
       "      <td>Фьючерсы на акции</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures_forts_currency</th>\n",
       "      <td>225</td>\n",
       "      <td>Фьючерсы на валюты</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures_forts_index</th>\n",
       "      <td>226</td>\n",
       "      <td>Фьючерсы на индексы</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures_forts_all</th>\n",
       "      <td>227</td>\n",
       "      <td>Все фьючерсы</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures_forts_interest</th>\n",
       "      <td>228</td>\n",
       "      <td>Фьючерсы на процентные ставки</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>futures_forts_ofz</th>\n",
       "      <td>260</td>\n",
       "      <td>Фьючерсы на ОФЗ</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>offboard_bonds_all</th>\n",
       "      <td>303</td>\n",
       "      <td>Все Коммерческие</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               id                            title  \\\n",
       "name                                                                 \n",
       "stock_shares_all                3                        Все акции   \n",
       "stock_bonds_all                 7                              Все   \n",
       "stock_shares_one              160                        Уровень 1   \n",
       "stock_shares_two              161                        Уровень 2   \n",
       "stock_shares_three            162                        Уровень 3   \n",
       "stock_bonds_one               163                    Все уровень 1   \n",
       "stock_bonds_two               164                    Все уровень 2   \n",
       "stock_bonds_three             165                    Все уровень 3   \n",
       "currency_selt_all_swap        170                  Все валюты СВОП   \n",
       "currency_selt_other_spot      171               Другие валюты СПОТ   \n",
       "currency_selt_eur_spot        172                     EUR/RUB СПОТ   \n",
       "currency_selt_usd_spot        173                     USD/RUB СПОТ   \n",
       "currency_selt_usd_swap        174                     USD/RUB СВОП   \n",
       "currency_selt_other_swap      175               Другие валюты СВОП   \n",
       "currency_selt_cny_swap        176                     CNY/RUB СВОП   \n",
       "currency_selt_all_spot        177                  Все валюты СПОТ   \n",
       "currency_selt_eurusd_spot     178                     EUR/USD СПОТ   \n",
       "currency_selt_eur_swap        179                     EUR/RUB СВОП   \n",
       "currency_selt_eurusd_swap     180                     EUR/USD СВОП   \n",
       "currency_selt_cny_spot        181                     CNY/RUB СПОТ   \n",
       "stock_exchange_corp_one       185               Биржевые уровень 1   \n",
       "stock_bonds_ofz_all           186                          Все ОФЗ   \n",
       "stock_bonds_ifi_two           187  Иностранных эмитентов уровень 2   \n",
       "stock_bonds_corp_three        188          Корпоративные уровень 3   \n",
       "stock_bonds_corp_all          189                Все корпоративные   \n",
       "stock_bonds_exchange_three    190               Биржевые уровень 3   \n",
       "stock_bonds_municipal_two     191          Муниципальные уровень 2   \n",
       "stock_bonds_subfederal_three  192           Субъектов РФ уровень 3   \n",
       "stock_bonds_cb_all            193                 Все Банка России   \n",
       "stock_bonds_corp_two          194          Корпоративные уровень 2   \n",
       "stock_bonds_exchange_two      195               Биржевые уровень 2   \n",
       "stock_bonds_ifi_three         196  Иностранных эмитентов уровень 3   \n",
       "stock_bonds_ifi_all           197        Все иностранных эмитентов   \n",
       "stock_bonds_subfederal_all    198                 Все субъектов РФ   \n",
       "stock_bonds_ifi_one           199  Иностранных эмитентов уровень 1   \n",
       "stock_bonds_exchange_all      200                     Все биржевые   \n",
       "stock_bonds_municipal_one     201          Муниципальные уровень 1   \n",
       "stock_bonds_corp_one          202          Корпоративные уровень 1   \n",
       "stock_bonds_municipal_three   203          Муниципальные уровень 3   \n",
       "stock_bonds_subfederal_two    204           Субъектов РФ уровень 2   \n",
       "stock_bonds_municipal_all     205                Все муниципальные   \n",
       "stock_bonds_subfederal_one    206           Субъектов РФ уровень 1   \n",
       "futures_forts_commodity       223   Фьючерсы на товарные контракты   \n",
       "futures_forts_shares          224                Фьючерсы на акции   \n",
       "futures_forts_currency        225               Фьючерсы на валюты   \n",
       "futures_forts_index           226              Фьючерсы на индексы   \n",
       "futures_forts_all             227                     Все фьючерсы   \n",
       "futures_forts_interest        228    Фьючерсы на процентные ставки   \n",
       "futures_forts_ofz             260                  Фьючерсы на ОФЗ   \n",
       "offboard_bonds_all            303                 Все Коммерческие   \n",
       "\n",
       "                              security_group_id  \n",
       "name                                             \n",
       "stock_shares_all                              4  \n",
       "stock_bonds_all                               3  \n",
       "stock_shares_one                              4  \n",
       "stock_shares_two                              4  \n",
       "stock_shares_three                            4  \n",
       "stock_bonds_one                               3  \n",
       "stock_bonds_two                               3  \n",
       "stock_bonds_three                             3  \n",
       "currency_selt_all_swap                        9  \n",
       "currency_selt_other_spot                      9  \n",
       "currency_selt_eur_spot                        9  \n",
       "currency_selt_usd_spot                        9  \n",
       "currency_selt_usd_swap                        9  \n",
       "currency_selt_other_swap                      9  \n",
       "currency_selt_cny_swap                        9  \n",
       "currency_selt_all_spot                        9  \n",
       "currency_selt_eurusd_spot                     9  \n",
       "currency_selt_eur_swap                        9  \n",
       "currency_selt_eurusd_swap                     9  \n",
       "currency_selt_cny_spot                        9  \n",
       "stock_exchange_corp_one                       3  \n",
       "stock_bonds_ofz_all                           3  \n",
       "stock_bonds_ifi_two                           3  \n",
       "stock_bonds_corp_three                        3  \n",
       "stock_bonds_corp_all                          3  \n",
       "stock_bonds_exchange_three                    3  \n",
       "stock_bonds_municipal_two                     3  \n",
       "stock_bonds_subfederal_three                  3  \n",
       "stock_bonds_cb_all                            3  \n",
       "stock_bonds_corp_two                          3  \n",
       "stock_bonds_exchange_two                      3  \n",
       "stock_bonds_ifi_three                         3  \n",
       "stock_bonds_ifi_all                           3  \n",
       "stock_bonds_subfederal_all                    3  \n",
       "stock_bonds_ifi_one                           3  \n",
       "stock_bonds_exchange_all                      3  \n",
       "stock_bonds_municipal_one                     3  \n",
       "stock_bonds_corp_one                          3  \n",
       "stock_bonds_municipal_three                   3  \n",
       "stock_bonds_subfederal_two                    3  \n",
       "stock_bonds_municipal_all                     3  \n",
       "stock_bonds_subfederal_one                    3  \n",
       "futures_forts_commodity                      10  \n",
       "futures_forts_shares                         10  \n",
       "futures_forts_currency                       10  \n",
       "futures_forts_index                          10  \n",
       "futures_forts_all                            10  \n",
       "futures_forts_interest                       10  \n",
       "futures_forts_ofz                            10  \n",
       "offboard_bonds_all                            3  "
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# collection\n",
    "set_group = {x['securitygroup'] for x in url_params if x.get('securitygroup')}\n",
    "display(GLOBAL_GUID.securitygroups.loc[list(set_group)]) #[].query(\"security_group_id==4\")\n",
    "GLOBAL_GUID.securitycollections.query(\"security_group_id.isin([10,3,4,9])\").sort_values('id')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "dc153786",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'engine': 'stock',\n",
       "  'market': 'shares',\n",
       "  'boardgroup': 'stock_shares_tplus',\n",
       "  'board': 'TQBR',\n",
       "  'securitygroup': 'stock_shares',\n",
       "  'collection': 'stock_shares_all'},\n",
       " {'engine': 'currency',\n",
       "  'market': 'selt',\n",
       "  'boardgroup': 'currency',\n",
       "  'board': 'CETS',\n",
       "  'securitygroup': 'currency_selt',\n",
       "  'collection': 'currency_selt_usd_spot'},\n",
       " {'engine': 'futures',\n",
       "  'market': 'forts',\n",
       "  'boardgroup': 'futures_forts',\n",
       "  'board': 'RFUD',\n",
       "  'securitygroup': 'futures_forts',\n",
       "  'collection': 'futures_forts_shares'},\n",
       " {'engine': 'state',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'state',\n",
       "  'board': 'MAIN',\n",
       "  'securitygroup': 'stock_bonds',\n",
       "  'collection': 'stock_bonds_ofz_all'},\n",
       " {'engine': 'commodity',\n",
       "  'market': 'futures',\n",
       "  'boardgroup': 'commodity_futures',\n",
       "  'board': 'FOCM',\n",
       "  'securitygroup': 'futures_forts'},\n",
       " {'engine': 'interventions',\n",
       "  'market': 'grain',\n",
       "  'boardgroup': 'interventions_grain',\n",
       "  'board': 'GSEL'},\n",
       " {'engine': 'offboard',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'offboard_bond_all',\n",
       "  'board': 'OBBO',\n",
       "  'securitygroup': 'stock_bonds',\n",
       "  'collection': 'stock_bonds_all'},\n",
       " {'engine': 'agro',\n",
       "  'market': 'sugar',\n",
       "  'boardgroup': 'agro_sugar_all',\n",
       "  'board': 'SUGR'},\n",
       " {'engine': 'otc',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'otc_bonds_tplus',\n",
       "  'board': 'OCTR',\n",
       "  'securitygroup': 'stock_bonds',\n",
       "  'collection': 'stock_bonds_all'}]"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Добавим collection (ручками)\n",
    "group_entity = {\n",
    "    \"stock\": \"stock_shares_all\",\n",
    "    \"currency\": \"currency_selt_usd_spot\",\n",
    "    \"futures\": \"futures_forts_shares\",\n",
    "    \"state\": \"stock_bonds_ofz_all\",\n",
    "    \"offboard\": \"stock_bonds_all\",\n",
    "    \"otc\": \"stock_bonds_all\",\n",
    "}\n",
    "for d in url_params:\n",
    "    if d['engine'] in group_entity:\n",
    "        d['collection'] = group_entity[d['engine']]\n",
    "url_params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "d26caf92",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'asset': 'Secid базового актива для опционов.',\n",
       " 'board': 'Код торговой площадки (режим торгов)',\n",
       " 'boardgroup': 'Группа торговых площадок',\n",
       " 'engine': 'Признак рынка (фондовый, валютный, срочный...)',\n",
       " 'market': 'Классфикация рынка: спот, индексы, рпс, репо, размещение, валюта и т.п.',\n",
       " 'securitygroup': 'Класс финансового инструмента',\n",
       " 'collection': 'Группировка финансовых инструментов по признакам (уровень, тип и тд). В словаре используется как securitycollection',\n",
       " 'datatype': 'securities or trades',\n",
       " 'event_id': 'ID мероприятия проводимого Мосбиржей. Идут в порядке возрастания. Только ближайшие события можно посмотреть на /iss/events',\n",
       " 'indexid': 'Код индекса (бенчмарка) публикуемого и/или расчитываемого Мосбиржей',\n",
       " 'news_id': 'Код новостной рассылки Мосбиржи. Реестр новостей можно увидить на /iss/sitenews',\n",
       " 'period': 'yearly, monthly или daily',\n",
       " 'report_name': 'Еженедельные отчеты по ВАЛЮТНЫМ (! только !) деривативам. По первичному анализу - OTC / c ЦК и нестандартные ПФИ. Нужны детали.',\n",
       " 'security': 'Secid финансового инструмента',\n",
       " 'session': 'Сессия торгов (утро, вечер, основная, итого)',\n",
       " 'ticker': 'Тикер бумаги в индексе долевых ФИ. По сути - Secid. Детали: /iss/statistics/engines/stock/markets/index/analytics/[indexid]/tickers',\n",
       " 'year': 'Год, только для архивов'}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ENTITY_DESCRIPTIONS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "9150fb41",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Дефолтные значения:\n",
    "for d in url_params:\n",
    "    d[\"datatype\"] = \"securities\"\n",
    "    d[\"event_id\"] = 10500\n",
    "    d[\"news_id\"] = 30000\n",
    "    d[\"period\"] = \"monthly\"\n",
    "    d[\"session\"] = 3\n",
    "    d[\"year\"] = 2022\n",
    "    d[\"ticker\"] = 'GAZP'\n",
    "    d[\"indexid\"] = \"RTSI\"\n",
    "url_params[2]['report_name'] = \"openpositions\"\n",
    "url_params[2]['asset'] = \"GAZP\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "b672a26b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# Остался SECID:\n",
    "url = (\n",
    "    \"http://iss.moex.com/iss/engines/{engine}/markets/{market}/boards/{board}/securities.json?iss.meta=off\"\n",
    "    \"&iss.only=securities&securities.columns=SECID,SHORTNAME,STATUS,SECTYPE,LISTLEVEL&securities.sort_column=LISTLEVEL\"\n",
    ")\n",
    "res_dict = {}\n",
    "for d in url_params:\n",
    "    res_dict[d[\"engine\"]] = requests.get(url.format(**d)).json()\n",
    "    time.sleep(.25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "7a7cd775",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['stock', 'currency', 'futures', 'state', 'commodity', 'interventions', 'offboard', 'agro', 'otc']\n"
     ]
    }
   ],
   "source": [
    "print([x['engine'] for x in url_params])\n",
    "secid_engine = {\n",
    "    \"stock\": \"GAZP\",\n",
    "    \"currency\": \"USDRUB_TMS\",\n",
    "    \"futures\": \"GZU5\",\n",
    "    \"state\": \"SU46023RMFS6\",\n",
    "    \"commodity\": \"FDEXW1RGG135\",\n",
    "    \"offboard\": \"RU000A103D03\",\n",
    "    \"agro\": \"SP_SG_PERL\",\n",
    "    \"otc\": \"RU000A0ZYYN4\"\n",
    "}\n",
    "url_params[8]['board'] = 'OCBR'\n",
    "url_params[8]['market'] = 'ndm'\n",
    "url_params[8]['boardgroup'] = \"otc_ndm_ccp_rub\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "af3b5e79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'engine': 'stock',\n",
       "  'market': 'shares',\n",
       "  'boardgroup': 'stock_shares_tplus',\n",
       "  'board': 'TQBR',\n",
       "  'securitygroup': 'stock_shares',\n",
       "  'collection': 'stock_shares_all',\n",
       "  'datatype': 'securities',\n",
       "  'event_id': 10500,\n",
       "  'news_id': 30000,\n",
       "  'period': 'monthly',\n",
       "  'session': 3,\n",
       "  'year': 2022,\n",
       "  'ticker': 'GAZP',\n",
       "  'indexid': 'RTSI',\n",
       "  'security': 'GAZP'},\n",
       " {'engine': 'currency',\n",
       "  'market': 'selt',\n",
       "  'boardgroup': 'currency',\n",
       "  'board': 'CETS',\n",
       "  'securitygroup': 'currency_selt',\n",
       "  'collection': 'currency_selt_usd_spot',\n",
       "  'datatype': 'securities',\n",
       "  'event_id': 10500,\n",
       "  'news_id': 30000,\n",
       "  'period': 'monthly',\n",
       "  'session': 3,\n",
       "  'year': 2022,\n",
       "  'ticker': 'GAZP',\n",
       "  'indexid': 'RTSI',\n",
       "  'security': 'USDRUB_TMS'},\n",
       " {'engine': 'futures',\n",
       "  'market': 'forts',\n",
       "  'boardgroup': 'futures_forts',\n",
       "  'board': 'RFUD',\n",
       "  'securitygroup': 'futures_forts',\n",
       "  'collection': 'futures_forts_shares',\n",
       "  'datatype': 'securities',\n",
       "  'event_id': 10500,\n",
       "  'news_id': 30000,\n",
       "  'period': 'monthly',\n",
       "  'session': 3,\n",
       "  'year': 2022,\n",
       "  'ticker': 'GAZP',\n",
       "  'indexid': 'RTSI',\n",
       "  'report_name': 'openpositions',\n",
       "  'asset': 'GAZP',\n",
       "  'security': 'GZU5'},\n",
       " {'engine': 'state',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'state',\n",
       "  'board': 'MAIN',\n",
       "  'securitygroup': 'stock_bonds',\n",
       "  'collection': 'stock_bonds_ofz_all',\n",
       "  'datatype': 'securities',\n",
       "  'event_id': 10500,\n",
       "  'news_id': 30000,\n",
       "  'period': 'monthly',\n",
       "  'session': 3,\n",
       "  'year': 2022,\n",
       "  'ticker': 'GAZP',\n",
       "  'indexid': 'RTSI',\n",
       "  'security': 'SU46023RMFS6'},\n",
       " {'engine': 'commodity',\n",
       "  'market': 'futures',\n",
       "  'boardgroup': 'commodity_futures',\n",
       "  'board': 'FOCM',\n",
       "  'securitygroup': 'futures_forts',\n",
       "  'datatype': 'securities',\n",
       "  'event_id': 10500,\n",
       "  'news_id': 30000,\n",
       "  'period': 'monthly',\n",
       "  'session': 3,\n",
       "  'year': 2022,\n",
       "  'ticker': 'GAZP',\n",
       "  'indexid': 'RTSI',\n",
       "  'security': 'FDEXW1RGG135'},\n",
       " {'engine': 'interventions',\n",
       "  'market': 'grain',\n",
       "  'boardgroup': 'interventions_grain',\n",
       "  'board': 'GSEL',\n",
       "  'datatype': 'securities',\n",
       "  'event_id': 10500,\n",
       "  'news_id': 30000,\n",
       "  'period': 'monthly',\n",
       "  'session': 3,\n",
       "  'year': 2022,\n",
       "  'ticker': 'GAZP',\n",
       "  'indexid': 'RTSI'},\n",
       " {'engine': 'offboard',\n",
       "  'market': 'bonds',\n",
       "  'boardgroup': 'offboard_bond_all',\n",
       "  'board': 'OBBO',\n",
       "  'securitygroup': 'stock_bonds',\n",
       "  'collection': 'stock_bonds_all',\n",
       "  'datatype': 'securities',\n",
       "  'event_id': 10500,\n",
       "  'news_id': 30000,\n",
       "  'period': 'monthly',\n",
       "  'session': 3,\n",
       "  'year': 2022,\n",
       "  'ticker': 'GAZP',\n",
       "  'indexid': 'RTSI',\n",
       "  'security': 'RU000A103D03'},\n",
       " {'engine': 'agro',\n",
       "  'market': 'sugar',\n",
       "  'boardgroup': 'agro_sugar_all',\n",
       "  'board': 'SUGR',\n",
       "  'datatype': 'securities',\n",
       "  'event_id': 10500,\n",
       "  'news_id': 30000,\n",
       "  'period': 'monthly',\n",
       "  'session': 3,\n",
       "  'year': 2022,\n",
       "  'ticker': 'GAZP',\n",
       "  'indexid': 'RTSI',\n",
       "  'security': 'SP_SG_PERL'},\n",
       " {'engine': 'otc',\n",
       "  'market': 'ndm',\n",
       "  'boardgroup': 'otc_ndm_ccp_rub',\n",
       "  'board': 'OCBR',\n",
       "  'securitygroup': 'stock_bonds',\n",
       "  'collection': 'stock_bonds_all',\n",
       "  'datatype': 'securities',\n",
       "  'event_id': 10500,\n",
       "  'news_id': 30000,\n",
       "  'period': 'monthly',\n",
       "  'session': 3,\n",
       "  'year': 2022,\n",
       "  'ticker': 'GAZP',\n",
       "  'indexid': 'RTSI',\n",
       "  'security': 'RU000A0ZYYN4'}]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for url in url_params:\n",
    "    if url['engine'] in secid_engine:\n",
    "        url['security'] = secid_engine[url['engine']]\n",
    "url_params"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42b1408a",
   "metadata": {},
   "source": [
    "### Первичный список параметров запроса готов. При необходимости скорректируем его"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac18bf64",
   "metadata": {},
   "source": [
    "План проверки эндпоинтов следующий\n",
    "1. Отсеить все поинты, доступные только для подписчиков\n",
    "2. Проверить, что поинты что-то получают.\n",
    "    - Если поинт что-то получил - сохранить результат, отметить результат как успешный\n",
    "    - Если поинт получил не 200 - отметить поинты с ошибкой\n",
    "    - Если поинт получил ошибку в данных (есть ключ с именем \"error\") - добавить поинт в проблемный\n",
    "3. Проверить результаты, повторить"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "0ca678bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Заведем словари для хранения, где ключ - id ссылки на описание API\n",
    "OK_API = {}\n",
    "BAD_API = {}\n",
    "UNAVAILABLE_API = {}\n",
    "ERROR_API = {}\n",
    "EMPTY_RESP_API = {}\n",
    "NOT_DATA_API = {}\n",
    "\n",
    "save_path = 'moex_api_response'\n",
    "\n",
    "if not os.path.exists(save_path):\n",
    "    os.mkdir(save_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "3ce7e1c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Пройдемся по все урлам без параметров:\n",
    "\n",
    "def find_error(json_res: dict):\n",
    "    for key, value in json_res.items():\n",
    "        if key == 'error' or (isinstance(value, dict) and find_error(value)):\n",
    "            return True\n",
    "    return False\n",
    "\n",
    "\n",
    "def check_null(json_res: dict):\n",
    "    for key, value in json_res.items():\n",
    "        if key == \"data\":\n",
    "            return (True, True) if value else (True, False)\n",
    "        if isinstance(value, dict): \n",
    "            is_find, res = check_null(value)\n",
    "            if is_find:\n",
    "                return is_find, res\n",
    "    return False, None\n",
    "\n",
    "\n",
    "def save_result(json_res: dict, api_id):\n",
    "    with open(save_path + '/' + str(api_id) + '.json', 'w') as outfile:\n",
    "        json.dump(json_res, outfile)\n",
    "        \n",
    "def check_url_in_result(api_id: int):\n",
    "    return any(api_id in dict_ for dict_ in [OK_API, BAD_API, UNAVAILABLE_API, ERROR_API, EMPTY_RESP_API, NOT_DATA_API])\n",
    "\n",
    "def check_api(url_data: MoexApi):\n",
    "    api_id = int(re.findall(r\"\\d+$\", url_data.url_faq)[-1])\n",
    "    if check_url_in_result(api_id):\n",
    "        return \n",
    "    \n",
    "    try:\n",
    "        resp = requests.get(url_data.url_template + '.json')\n",
    "        resp_json = resp.json()\n",
    "    except:\n",
    "        UNAVAILABLE_API[api_id] = url_data\n",
    "        return\n",
    "        \n",
    "    if resp.status_code != 200:\n",
    "        BAD_API[api_id] = [url_data, resp_json]\n",
    "        return\n",
    "\n",
    "    if find_error(resp_json):\n",
    "        ERROR_API[api_id] = [url_data, resp_json]\n",
    "        return\n",
    "    \n",
    "    is_find, res = check_null(resp_json)\n",
    "    if not is_find:\n",
    "        NOT_DATA_API[api_id] = [url_data, resp_json]\n",
    "    elif not res:\n",
    "        EMPTY_RESP_API[api_id] = [url_data, resp_json]\n",
    "    else:\n",
    "        OK_API[api_id] = url_data\n",
    "        \n",
    "    save_result(resp_json, api_id)\n",
    "        \n",
    "    \n",
    "for url_data in FINAL_DATA:\n",
    "    if url_data.url_template.find('{') == -1:\n",
    "        check_api(url_data)\n",
    "        time.sleep(.25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "52137886",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{} {} {} {}\n"
     ]
    }
   ],
   "source": [
    "print(BAD_API, ERROR_API, EMPTY_RESP_API, NOT_DATA_API)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "06a42108",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[MoexApi(url_faq='http://iss.moex.com/iss/reference/5', url_template='http://iss.moex.com/iss/securities', description='Список бумаг торгуемых на московской бирже.'), MoexApi(url_faq='http://iss.moex.com/iss/reference/24', url_template='http://iss.moex.com/iss/turnovers', description='Получить сводные обороты по рынкам.Например: https://iss.moex.com/iss/turnovers.xml'), MoexApi(url_faq='http://iss.moex.com/iss/reference/100', url_template='http://iss.moex.com/iss/turnovers/columns', description='Получить описание полей для запросов оборотов по рынку/торговой системе.\\rНапример: https://iss.moex.com/iss/engines/stock/turnovers/columns.xml'), MoexApi(url_faq='http://iss.moex.com/iss/reference/28', url_template='http://iss.moex.com/iss/index', description='Получить глобальные справочники ISS. \\rНапример: https://iss.moex.com/iss/index.xml'), MoexApi(url_faq='http://iss.moex.com/iss/reference/40', url_template='http://iss.moex.com/iss/engines', description='Получить доступные торговые системы. Например: https://iss.moex.com/iss/engines.xml')]\n",
      "Всего: 38\n"
     ]
    }
   ],
   "source": [
    "print(list(OK_API.values())[:5])\n",
    "print(\"Всего:\", len(OK_API))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "e84e692c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{833: MoexApi(url_faq='http://iss.moex.com/iss/reference/833', url_template='http://iss.moex.com/iss/history/otc/providers/nsd/markets', description='Обобщенные данные ОТС ПФИ и РЕПО - список рынков.'), 841: MoexApi(url_faq='http://iss.moex.com/iss/reference/841', url_template='http://iss.moex.com/iss/statistics/engines/stock/securitieslisting', description='Таблица соответствия торгуемых ценных бумаг по режимам торгов'), 905: MoexApi(url_faq='http://iss.moex.com/iss/reference/905', url_template='http://iss.moex.com/iss/statistics/complex/securities', description='Маркировка сложных финансовых инструментов')}\n",
      "Всего: 3\n"
     ]
    }
   ],
   "source": [
    "print(UNAVAILABLE_API)  # Прочекал доп. глазами\n",
    "print(\"Всего:\", len(UNAVAILABLE_API))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f897be68",
   "metadata": {},
   "source": [
    "#### Теперь прочекаем урлы с вшитыми параметрами\n",
    "Логика как и без них, но если подставить в УРЛ недопустимые параметры (например, урл только для индексов, а подставляем цб) то можем получить ошибку или пустые данные. В этом случае нам нужно взять следующий массив из готовых параметров и протестить на них, пока не получим нужные нам данные.\n",
    "Для дальнейшего анализа и оптимизации, сохраним engine набора параметров для успешных запросов.\n",
    "Пустому ответу отадаем приоритет выше, чем ответу с ошибкой (+ сохраним engine набора, по которому вернули пустые данные)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "40e3da42",
   "metadata": {},
   "outputs": [],
   "source": [
    "OK_ENGINE = {}\n",
    "EMPTY_ENGINE = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "b60d31a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# url_params\n",
    "def check_api_with_params(url_data: MoexApi):\n",
    "    api_id = int(re.findall(r\"\\d+$\", url_data.url_faq)[-1])\n",
    "    if check_url_in_result(api_id):\n",
    "        return \n",
    "    \n",
    "    tmp_error_json = None\n",
    "    tmp_empty_json = None\n",
    "    tmp_engine = None\n",
    "    \n",
    "    for params in url_params:\n",
    "        \n",
    "        try:\n",
    "            use_url = url_data.url_template.format(**params)\n",
    "        except KeyError:\n",
    "            continue\n",
    "        \n",
    "        try:\n",
    "            time.sleep(.25)\n",
    "            resp = requests.get(use_url + '.json')\n",
    "            resp_json = resp.json()\n",
    "        except json.JSONDecodeError:\n",
    "            UNAVAILABLE_API[api_id] = url_data\n",
    "            return\n",
    "        \n",
    "        if resp.status_code != 200:\n",
    "            BAD_API[api_id] = [url_data, resp_json]\n",
    "            return\n",
    "\n",
    "        if find_error(resp_json):\n",
    "            if tmp_empty_json is None and tmp_error_json is None:\n",
    "                tmp_error_json = resp_json\n",
    "                tmp_engine = params['engine']\n",
    "            continue\n",
    "\n",
    "        is_find, res = check_null(resp_json)\n",
    "        if not is_find:\n",
    "            NOT_DATA_API[api_id] = [url_data, resp_json]\n",
    "        elif not res:\n",
    "            if tmp_empty_json is None:\n",
    "                tmp_empty_json = resp_json\n",
    "                tmp_engine = params['engine']\n",
    "            continue\n",
    "        else:\n",
    "            OK_API[api_id] = url_data\n",
    "            OK_ENGINE[api_id] = params['engine']\n",
    "            save_result(resp_json, api_id)\n",
    "            return\n",
    "    \n",
    "    if tmp_engine is None:\n",
    "        print(\"For urls\", url_data, \"not found params\")\n",
    "    elif tmp_empty_json:\n",
    "        EMPTY_RESP_API[api_id] = [url_data, tmp_empty_json]\n",
    "        EMPTY_ENGINE[api_id] = tmp_engine\n",
    "        save_result(tmp_empty_json, api_id)\n",
    "    else:\n",
    "        ERROR_API[api_id] = [url_data, tmp_error_json]\n",
    "        save_result(tmp_error_json, api_id)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "b6902006",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For urls MoexApi(url_faq='http://iss.moex.com/iss/reference/789', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/.*?{securities}/columns', description='Получить описание полей для запросов исторических данных по бумагам для рынка.') not found params\n"
     ]
    }
   ],
   "source": [
    "for url_data in FINAL_DATA:\n",
    "    if url_data.url_template.find('{') != -1:\n",
    "        check_api_with_params(url_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "ef4002bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{158: [MoexApi(url_faq='http://iss.moex.com/iss/reference/158', url_template='http://iss.moex.com/iss/engines/{engine}/markets/{market}/boardgroups/{boardgroup}/securities/{security}/candleborders', description=''),\n",
       "  {'borders': {'metadata': {'begin': {'type': 'datetime',\n",
       "      'bytes': 57,\n",
       "      'max_size': 0},\n",
       "     'end': {'type': 'datetime', 'bytes': 57, 'max_size': 0},\n",
       "     'interval': {'type': 'int32'},\n",
       "     'board_group_id': {'type': 'int32'}},\n",
       "    'columns': ['begin', 'end', 'interval', 'board_group_id'],\n",
       "    'data': []}}],\n",
       " 759: [MoexApi(url_faq='http://iss.moex.com/iss/reference/759', url_template='http://iss.moex.com/iss/statistics/engines/stock/splits/{security}', description=''),\n",
       "  {'splits': {'metadata': {'tradedate': {'type': 'date',\n",
       "      'bytes': 10,\n",
       "      'max_size': 0},\n",
       "     'secid': {'type': 'string', 'bytes': 36, 'max_size': 0},\n",
       "     'before': {'type': 'int32'},\n",
       "     'after': {'type': 'int32'}},\n",
       "    'columns': ['tradedate', 'secid', 'before', 'after'],\n",
       "    'data': []}}],\n",
       " 149: [MoexApi(url_faq='http://iss.moex.com/iss/reference/149', url_template='http://iss.moex.com/iss/statistics/engines/stock/markets/index/analytics/{indexid}/tickers/{ticker}', description='Информация по тикеру'),\n",
       "  {'ticker': {'metadata': {'indexid': {'type': 'string',\n",
       "      'bytes': 36,\n",
       "      'max_size': 0},\n",
       "     'tradedate': {'type': 'date', 'bytes': 10, 'max_size': 0},\n",
       "     'ticker': {'type': 'string', 'bytes': 36, 'max_size': 0},\n",
       "     'shortnames': {'type': 'undefined', 'bytes': 9216, 'max_size': 0},\n",
       "     'secids': {'type': 'undefined', 'bytes': 3072, 'max_size': 0},\n",
       "     'waprice': {'type': 'double'},\n",
       "     'issue_size_total': {'type': 'double'},\n",
       "     'cap_total': {'type': 'double'},\n",
       "     'ff_factor': {'type': 'double'},\n",
       "     'w_factor': {'type': 'double'},\n",
       "     'issue_size_index': {'type': 'double'},\n",
       "     'cap_index': {'type': 'double'},\n",
       "     'weight': {'type': 'double'},\n",
       "     'value': {'type': 'double'},\n",
       "     'num_trades': {'type': 'int64'},\n",
       "     'volatility': {'type': 'double'},\n",
       "     'factora': {'type': 'double'},\n",
       "     'factorb': {'type': 'double'},\n",
       "     'influence': {'type': 'double'},\n",
       "     'determinat': {'type': 'double'},\n",
       "     'tradingsession': {'type': 'int32'}},\n",
       "    'columns': ['indexid',\n",
       "     'tradedate',\n",
       "     'ticker',\n",
       "     'shortnames',\n",
       "     'secids',\n",
       "     'waprice',\n",
       "     'issue_size_total',\n",
       "     'cap_total',\n",
       "     'ff_factor',\n",
       "     'w_factor',\n",
       "     'issue_size_index',\n",
       "     'cap_index',\n",
       "     'weight',\n",
       "     'value',\n",
       "     'num_trades',\n",
       "     'volatility',\n",
       "     'factora',\n",
       "     'factorb',\n",
       "     'influence',\n",
       "     'determinat',\n",
       "     'tradingsession'],\n",
       "    'data': []},\n",
       "   'ticker.cursor': {'metadata': {'INDEX': {'type': 'int64'},\n",
       "     'TOTAL': {'type': 'int64'},\n",
       "     'PAGESIZE': {'type': 'int64'}},\n",
       "    'columns': ['INDEX', 'TOTAL', 'PAGESIZE'],\n",
       "    'data': [[0, 0, 20]]}}],\n",
       " 163: [MoexApi(url_faq='http://iss.moex.com/iss/reference/163', url_template='http://iss.moex.com/iss/history/engines/stock/totals/boards/{board}/securities', description='Обобщенная информация по фондовому рынку по выбранному режиму'),\n",
       "  {'securities': {'metadata': {'SECID': {'type': 'string',\n",
       "      'bytes': 36,\n",
       "      'max_size': 0},\n",
       "     'TRADEDATE': {'type': 'date', 'bytes': 10, 'max_size': 0},\n",
       "     'BOARDID': {'type': 'string', 'bytes': 12, 'max_size': 0},\n",
       "     'CURRENCYID': {'type': 'string', 'bytes': 9, 'max_size': 0},\n",
       "     'OPEN': {'type': 'double'},\n",
       "     'HIGH': {'type': 'double'},\n",
       "     'LOW': {'type': 'double'},\n",
       "     'CLOSE': {'type': 'double'},\n",
       "     'WAPRICE': {'type': 'double'},\n",
       "     'MARKETPRICE2': {'type': 'double'},\n",
       "     'ADMITTEDQUOTE': {'type': 'double'},\n",
       "     'TRENDCLOSE': {'type': 'double'},\n",
       "     'TRENDWAP': {'type': 'double'},\n",
       "     'TRENDWAPPR': {'type': 'double'},\n",
       "     'VOLUME': {'type': 'double'},\n",
       "     'VALUE': {'type': 'double'},\n",
       "     'NUMTRADES': {'type': 'int32'},\n",
       "     'OPENVAL': {'type': 'double'},\n",
       "     'CLOSEVAL': {'type': 'double'},\n",
       "     'ISSUESIZE': {'type': 'double'},\n",
       "     'FACEVALUE': {'type': 'double'},\n",
       "     'DAILYCAPITALIZATION': {'type': 'double'},\n",
       "     'MONTHLYCAPITALIZATION': {'type': 'double'},\n",
       "     'MP2VALTRD': {'type': 'double'},\n",
       "     'ADMITTEDVALUE': {'type': 'double'},\n",
       "     'MARKETPRICE3': {'type': 'double'},\n",
       "     'MARKETPRICE3TRADESVALUE': {'type': 'double'},\n",
       "     'LISTNAME': {'type': 'string', 'bytes': 6, 'max_size': 0},\n",
       "     'SYSTIME': {'type': 'datetime', 'bytes': 19, 'max_size': 0},\n",
       "     'TRADINGSESSION': {'type': 'int32'}},\n",
       "    'columns': ['SECID',\n",
       "     'TRADEDATE',\n",
       "     'BOARDID',\n",
       "     'CURRENCYID',\n",
       "     'OPEN',\n",
       "     'HIGH',\n",
       "     'LOW',\n",
       "     'CLOSE',\n",
       "     'WAPRICE',\n",
       "     'MARKETPRICE2',\n",
       "     'ADMITTEDQUOTE',\n",
       "     'TRENDCLOSE',\n",
       "     'TRENDWAP',\n",
       "     'TRENDWAPPR',\n",
       "     'VOLUME',\n",
       "     'VALUE',\n",
       "     'NUMTRADES',\n",
       "     'OPENVAL',\n",
       "     'CLOSEVAL',\n",
       "     'ISSUESIZE',\n",
       "     'FACEVALUE',\n",
       "     'DAILYCAPITALIZATION',\n",
       "     'MONTHLYCAPITALIZATION',\n",
       "     'MP2VALTRD',\n",
       "     'ADMITTEDVALUE',\n",
       "     'MARKETPRICE3',\n",
       "     'MARKETPRICE3TRADESVALUE',\n",
       "     'LISTNAME',\n",
       "     'SYSTIME',\n",
       "     'TRADINGSESSION'],\n",
       "    'data': []},\n",
       "   'securities.cursor': {'metadata': {'INDEX': {'type': 'int64'},\n",
       "     'TOTAL': {'type': 'int64'},\n",
       "     'PAGESIZE': {'type': 'int64'}},\n",
       "    'columns': ['INDEX', 'TOTAL', 'PAGESIZE'],\n",
       "    'data': [[0, 0, 10000]]},\n",
       "   'securities.dates': {'metadata': {'from': {'type': 'date',\n",
       "      'bytes': 30,\n",
       "      'max_size': 0},\n",
       "     'till': {'type': 'date', 'bytes': 30, 'max_size': 0}},\n",
       "    'columns': ['from', 'till'],\n",
       "    'data': [[None, None]]}}],\n",
       " 164: [MoexApi(url_faq='http://iss.moex.com/iss/reference/164', url_template='http://iss.moex.com/iss/history/engines/stock/totals/boards/{board}/securities/{security}', description='Обобщенная информация по фондовому рынку по выбранному режиму и инструменту'),\n",
       "  {'security': {'metadata': {'SECID': {'type': 'string',\n",
       "      'bytes': 36,\n",
       "      'max_size': 0},\n",
       "     'TRADEDATE': {'type': 'date', 'bytes': 10, 'max_size': 0},\n",
       "     'BOARDID': {'type': 'string', 'bytes': 12, 'max_size': 0},\n",
       "     'CURRENCYID': {'type': 'string', 'bytes': 9, 'max_size': 0},\n",
       "     'OPEN': {'type': 'double'},\n",
       "     'HIGH': {'type': 'double'},\n",
       "     'LOW': {'type': 'double'},\n",
       "     'CLOSE': {'type': 'double'},\n",
       "     'WAPRICE': {'type': 'double'},\n",
       "     'MARKETPRICE2': {'type': 'double'},\n",
       "     'ADMITTEDQUOTE': {'type': 'double'},\n",
       "     'TRENDCLOSE': {'type': 'double'},\n",
       "     'TRENDWAP': {'type': 'double'},\n",
       "     'TRENDWAPPR': {'type': 'double'},\n",
       "     'VOLUME': {'type': 'double'},\n",
       "     'VALUE': {'type': 'double'},\n",
       "     'NUMTRADES': {'type': 'int32'},\n",
       "     'OPENVAL': {'type': 'double'},\n",
       "     'CLOSEVAL': {'type': 'double'},\n",
       "     'ISSUESIZE': {'type': 'double'},\n",
       "     'FACEVALUE': {'type': 'double'},\n",
       "     'DAILYCAPITALIZATION': {'type': 'double'},\n",
       "     'MONTHLYCAPITALIZATION': {'type': 'double'},\n",
       "     'MP2VALTRD': {'type': 'double'},\n",
       "     'ADMITTEDVALUE': {'type': 'double'},\n",
       "     'MARKETPRICE3': {'type': 'double'},\n",
       "     'MARKETPRICE3TRADESVALUE': {'type': 'double'},\n",
       "     'LISTNAME': {'type': 'string', 'bytes': 6, 'max_size': 0},\n",
       "     'SYSTIME': {'type': 'datetime', 'bytes': 19, 'max_size': 0},\n",
       "     'TRADINGSESSION': {'type': 'int32'}},\n",
       "    'columns': ['SECID',\n",
       "     'TRADEDATE',\n",
       "     'BOARDID',\n",
       "     'CURRENCYID',\n",
       "     'OPEN',\n",
       "     'HIGH',\n",
       "     'LOW',\n",
       "     'CLOSE',\n",
       "     'WAPRICE',\n",
       "     'MARKETPRICE2',\n",
       "     'ADMITTEDQUOTE',\n",
       "     'TRENDCLOSE',\n",
       "     'TRENDWAP',\n",
       "     'TRENDWAPPR',\n",
       "     'VOLUME',\n",
       "     'VALUE',\n",
       "     'NUMTRADES',\n",
       "     'OPENVAL',\n",
       "     'CLOSEVAL',\n",
       "     'ISSUESIZE',\n",
       "     'FACEVALUE',\n",
       "     'DAILYCAPITALIZATION',\n",
       "     'MONTHLYCAPITALIZATION',\n",
       "     'MP2VALTRD',\n",
       "     'ADMITTEDVALUE',\n",
       "     'MARKETPRICE3',\n",
       "     'MARKETPRICE3TRADESVALUE',\n",
       "     'LISTNAME',\n",
       "     'SYSTIME',\n",
       "     'TRADINGSESSION'],\n",
       "    'data': []},\n",
       "   'security.cursor': {'metadata': {'INDEX': {'type': 'int64'},\n",
       "     'TOTAL': {'type': 'int64'},\n",
       "     'PAGESIZE': {'type': 'int64'}},\n",
       "    'columns': ['INDEX', 'TOTAL', 'PAGESIZE'],\n",
       "    'data': [[0, 0, 5000]]},\n",
       "   'security.dates': {'metadata': {'from': {'type': 'date',\n",
       "      'bytes': 30,\n",
       "      'max_size': 0},\n",
       "     'till': {'type': 'date', 'bytes': 30, 'max_size': 0}},\n",
       "    'columns': ['from', 'till'],\n",
       "    'data': [[None, None]]}}],\n",
       " 715: [MoexApi(url_faq='http://iss.moex.com/iss/reference/715', url_template='http://iss.moex.com/iss/statistics/engines/currency/markets/fixing/{security}', description='Фиксинги Московской биржи'),\n",
       "  {'history': {'metadata': {'tradedate': {'type': 'date',\n",
       "      'bytes': 10,\n",
       "      'max_size': 0},\n",
       "     'secid': {'type': 'string', 'bytes': 36, 'max_size': 0},\n",
       "     'rate': {'type': 'double'}},\n",
       "    'columns': ['tradedate', 'secid', 'rate'],\n",
       "    'data': []},\n",
       "   'history.cursor': {'metadata': {'INDEX': {'type': 'int64'},\n",
       "     'TOTAL': {'type': 'int64'},\n",
       "     'PAGESIZE': {'type': 'int64'}},\n",
       "    'columns': ['INDEX', 'TOTAL', 'PAGESIZE'],\n",
       "    'data': [[0, 0, 100]]},\n",
       "   'history.dates': {'metadata': {'from': {'type': 'date',\n",
       "      'bytes': 30,\n",
       "      'max_size': 0},\n",
       "     'till': {'type': 'date', 'bytes': 30, 'max_size': 0}},\n",
       "    'columns': ['from', 'till'],\n",
       "    'data': [[None, None]]}}],\n",
       " 712: [MoexApi(url_faq='http://iss.moex.com/iss/reference/712', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/indicativerates/securities/{security}', description='Индикативный курс валют срочного рынка'),\n",
       "  {'securities': {'metadata': {'tradedate': {'type': 'date',\n",
       "      'bytes': 10,\n",
       "      'max_size': 0},\n",
       "     'tradetime': {'type': 'string', 'bytes': 24, 'max_size': 0},\n",
       "     'secid': {'type': 'string', 'bytes': 36, 'max_size': 0},\n",
       "     'rate': {'type': 'double'}},\n",
       "    'columns': ['tradedate', 'tradetime', 'secid', 'rate'],\n",
       "    'data': []},\n",
       "   'securities.cursor': {'metadata': {'INDEX': {'type': 'int64'},\n",
       "     'TOTAL': {'type': 'int64'},\n",
       "     'PAGESIZE': {'type': 'int64'}},\n",
       "    'columns': ['INDEX', 'TOTAL', 'PAGESIZE'],\n",
       "    'data': [[0, 0, 100]]},\n",
       "   'securities.dates': {'metadata': {'from': {'type': 'date',\n",
       "      'bytes': 30,\n",
       "      'max_size': 0},\n",
       "     'till': {'type': 'date', 'bytes': 30, 'max_size': 0}},\n",
       "    'columns': ['from', 'till'],\n",
       "    'data': [[None, None]]}}],\n",
       " 861: [MoexApi(url_faq='http://iss.moex.com/iss/reference/861', url_template='http://iss.moex.com/iss/analyticalproducts/curves/securities/{security}', description='Будущие ставки для ценообразования нестандартных инструментов (деривативов)'),\n",
       "  {'curves': {'metadata': {'tradedate': {'type': 'date',\n",
       "      'bytes': 10,\n",
       "      'max_size': 0},\n",
       "     'tradetime': {'type': 'time', 'bytes': 10, 'max_size': 0},\n",
       "     'group': {'type': 'string', 'bytes': 75, 'max_size': 0},\n",
       "     'secid': {'type': 'string', 'bytes': 75, 'max_size': 0},\n",
       "     'term': {'type': 'string', 'bytes': 15, 'max_size': 0},\n",
       "     'value': {'type': 'double'},\n",
       "     'systime': {'type': 'datetime', 'bytes': 19, 'max_size': 0}},\n",
       "    'columns': ['tradedate',\n",
       "     'tradetime',\n",
       "     'group',\n",
       "     'secid',\n",
       "     'term',\n",
       "     'value',\n",
       "     'systime'],\n",
       "    'data': []}}]}"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EMPTY_RESP_API"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "d01a5f1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "104"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(OK_API)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "1a28c4df",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "UNAVAILABLE_API"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a77fef8f",
   "metadata": {},
   "source": [
    "### В целом, недоступные урлы найдены корректно. \n",
    "Описание полей нас не особо интересует. Часть аналитики и заявки - недоступны без подписки!"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "161abea7",
   "metadata": {},
   "source": [
    "### API c ошибками:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "34d56ae7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{120: [MoexApi(url_faq='http://iss.moex.com/iss/reference/120', url_template='http://iss.moex.com/iss/history/engines/{engine}/markets/{market}/boardgroups/{boardgroup}/listing', description='Получить данные по листингу бумаг в историческом разрезе по указанной группе режимов'),\n",
       "  {'securities': {'error': 'Error while acquiring data.'}}],\n",
       " 219: [MoexApi(url_faq='http://iss.moex.com/iss/reference/219', url_template='http://iss.moex.com/iss/statistics/engines/{engine}/derivatives/{report_name}', description='Еженедельные отчеты по валютным деривативам:\\r\\rnumtrades - Информация о количестве договоров по инструментам, являющимся производными финансовыми инструментами (по валютным парам)\\rparticipants - Информация о количестве лиц, имеющих открытые позиции по инструментам, являющимся производными финансовыми инструментами (по валютным парам)\\ropenpositions - Информация об открытых позициях по инструментам, являющимся производными финансовыми инструментами (по валютным парам)\\rexpirationparticipants - Информация о количестве лиц, имеющих открытые позиции по договорам, являющимся производными финансовыми инструментами (по срокам экспирации)\\rexpirationopenpositions - Информация об объеме открытых позиций по договорам, являющимся производными финансовыми инструментами (по срокам экспирации)'),\n",
       "  {'columns': {'error': 'Error while acquiring data.'},\n",
       "   'data': {'error': 'Error while acquiring data.'}}],\n",
       " 220: [MoexApi(url_faq='http://iss.moex.com/iss/reference/220', url_template='http://iss.moex.com/iss/statistics/engines/{engine}/monthly/{report_name}', description=''),\n",
       "  {'columns': {'error': 'Error while acquiring data.'},\n",
       "   'data': {'error': 'Error while acquiring data.'}}]}"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ERROR_API"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d89c59cb",
   "metadata": {},
   "source": [
    "1. Листинг в историческом разрезе нас не интересует.\n",
    "2. Отчеты по валютных деривативам выдают результат, при выборе engine='currency'. Но без деталей - поинт бесполезный (либо пустой результат либо объемы несопоставимы с оборотом срочки)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "099b8f55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ТОП! ВСЕ ОТВЕТЫ СТАНДАРТНОГО ВИДА!!!\n",
    "NOT_DATA_API "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "1f7d7935",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{158: [MoexApi(url_faq='http://iss.moex.com/iss/reference/158', url_template='http://iss.moex.com/iss/engines/{engine}/markets/{market}/boardgroups/{boardgroup}/securities/{security}/candleborders', description=''),\n",
       "  {'borders': {'metadata': {'begin': {'type': 'datetime',\n",
       "      'bytes': 57,\n",
       "      'max_size': 0},\n",
       "     'end': {'type': 'datetime', 'bytes': 57, 'max_size': 0},\n",
       "     'interval': {'type': 'int32'},\n",
       "     'board_group_id': {'type': 'int32'}},\n",
       "    'columns': ['begin', 'end', 'interval', 'board_group_id'],\n",
       "    'data': []}}],\n",
       " 759: [MoexApi(url_faq='http://iss.moex.com/iss/reference/759', url_template='http://iss.moex.com/iss/statistics/engines/stock/splits/{security}', description=''),\n",
       "  {'splits': {'metadata': {'tradedate': {'type': 'date',\n",
       "      'bytes': 10,\n",
       "      'max_size': 0},\n",
       "     'secid': {'type': 'string', 'bytes': 36, 'max_size': 0},\n",
       "     'before': {'type': 'int32'},\n",
       "     'after': {'type': 'int32'}},\n",
       "    'columns': ['tradedate', 'secid', 'before', 'after'],\n",
       "    'data': []}}],\n",
       " 149: [MoexApi(url_faq='http://iss.moex.com/iss/reference/149', url_template='http://iss.moex.com/iss/statistics/engines/stock/markets/index/analytics/{indexid}/tickers/{ticker}', description='Информация по тикеру'),\n",
       "  {'ticker': {'metadata': {'indexid': {'type': 'string',\n",
       "      'bytes': 36,\n",
       "      'max_size': 0},\n",
       "     'tradedate': {'type': 'date', 'bytes': 10, 'max_size': 0},\n",
       "     'ticker': {'type': 'string', 'bytes': 36, 'max_size': 0},\n",
       "     'shortnames': {'type': 'undefined', 'bytes': 9216, 'max_size': 0},\n",
       "     'secids': {'type': 'undefined', 'bytes': 3072, 'max_size': 0},\n",
       "     'waprice': {'type': 'double'},\n",
       "     'issue_size_total': {'type': 'double'},\n",
       "     'cap_total': {'type': 'double'},\n",
       "     'ff_factor': {'type': 'double'},\n",
       "     'w_factor': {'type': 'double'},\n",
       "     'issue_size_index': {'type': 'double'},\n",
       "     'cap_index': {'type': 'double'},\n",
       "     'weight': {'type': 'double'},\n",
       "     'value': {'type': 'double'},\n",
       "     'num_trades': {'type': 'int64'},\n",
       "     'volatility': {'type': 'double'},\n",
       "     'factora': {'type': 'double'},\n",
       "     'factorb': {'type': 'double'},\n",
       "     'influence': {'type': 'double'},\n",
       "     'determinat': {'type': 'double'},\n",
       "     'tradingsession': {'type': 'int32'}},\n",
       "    'columns': ['indexid',\n",
       "     'tradedate',\n",
       "     'ticker',\n",
       "     'shortnames',\n",
       "     'secids',\n",
       "     'waprice',\n",
       "     'issue_size_total',\n",
       "     'cap_total',\n",
       "     'ff_factor',\n",
       "     'w_factor',\n",
       "     'issue_size_index',\n",
       "     'cap_index',\n",
       "     'weight',\n",
       "     'value',\n",
       "     'num_trades',\n",
       "     'volatility',\n",
       "     'factora',\n",
       "     'factorb',\n",
       "     'influence',\n",
       "     'determinat',\n",
       "     'tradingsession'],\n",
       "    'data': []},\n",
       "   'ticker.cursor': {'metadata': {'INDEX': {'type': 'int64'},\n",
       "     'TOTAL': {'type': 'int64'},\n",
       "     'PAGESIZE': {'type': 'int64'}},\n",
       "    'columns': ['INDEX', 'TOTAL', 'PAGESIZE'],\n",
       "    'data': [[0, 0, 20]]}}],\n",
       " 163: [MoexApi(url_faq='http://iss.moex.com/iss/reference/163', url_template='http://iss.moex.com/iss/history/engines/stock/totals/boards/{board}/securities', description='Обобщенная информация по фондовому рынку по выбранному режиму'),\n",
       "  {'securities': {'metadata': {'SECID': {'type': 'string',\n",
       "      'bytes': 36,\n",
       "      'max_size': 0},\n",
       "     'TRADEDATE': {'type': 'date', 'bytes': 10, 'max_size': 0},\n",
       "     'BOARDID': {'type': 'string', 'bytes': 12, 'max_size': 0},\n",
       "     'CURRENCYID': {'type': 'string', 'bytes': 9, 'max_size': 0},\n",
       "     'OPEN': {'type': 'double'},\n",
       "     'HIGH': {'type': 'double'},\n",
       "     'LOW': {'type': 'double'},\n",
       "     'CLOSE': {'type': 'double'},\n",
       "     'WAPRICE': {'type': 'double'},\n",
       "     'MARKETPRICE2': {'type': 'double'},\n",
       "     'ADMITTEDQUOTE': {'type': 'double'},\n",
       "     'TRENDCLOSE': {'type': 'double'},\n",
       "     'TRENDWAP': {'type': 'double'},\n",
       "     'TRENDWAPPR': {'type': 'double'},\n",
       "     'VOLUME': {'type': 'double'},\n",
       "     'VALUE': {'type': 'double'},\n",
       "     'NUMTRADES': {'type': 'int32'},\n",
       "     'OPENVAL': {'type': 'double'},\n",
       "     'CLOSEVAL': {'type': 'double'},\n",
       "     'ISSUESIZE': {'type': 'double'},\n",
       "     'FACEVALUE': {'type': 'double'},\n",
       "     'DAILYCAPITALIZATION': {'type': 'double'},\n",
       "     'MONTHLYCAPITALIZATION': {'type': 'double'},\n",
       "     'MP2VALTRD': {'type': 'double'},\n",
       "     'ADMITTEDVALUE': {'type': 'double'},\n",
       "     'MARKETPRICE3': {'type': 'double'},\n",
       "     'MARKETPRICE3TRADESVALUE': {'type': 'double'},\n",
       "     'LISTNAME': {'type': 'string', 'bytes': 6, 'max_size': 0},\n",
       "     'SYSTIME': {'type': 'datetime', 'bytes': 19, 'max_size': 0},\n",
       "     'TRADINGSESSION': {'type': 'int32'}},\n",
       "    'columns': ['SECID',\n",
       "     'TRADEDATE',\n",
       "     'BOARDID',\n",
       "     'CURRENCYID',\n",
       "     'OPEN',\n",
       "     'HIGH',\n",
       "     'LOW',\n",
       "     'CLOSE',\n",
       "     'WAPRICE',\n",
       "     'MARKETPRICE2',\n",
       "     'ADMITTEDQUOTE',\n",
       "     'TRENDCLOSE',\n",
       "     'TRENDWAP',\n",
       "     'TRENDWAPPR',\n",
       "     'VOLUME',\n",
       "     'VALUE',\n",
       "     'NUMTRADES',\n",
       "     'OPENVAL',\n",
       "     'CLOSEVAL',\n",
       "     'ISSUESIZE',\n",
       "     'FACEVALUE',\n",
       "     'DAILYCAPITALIZATION',\n",
       "     'MONTHLYCAPITALIZATION',\n",
       "     'MP2VALTRD',\n",
       "     'ADMITTEDVALUE',\n",
       "     'MARKETPRICE3',\n",
       "     'MARKETPRICE3TRADESVALUE',\n",
       "     'LISTNAME',\n",
       "     'SYSTIME',\n",
       "     'TRADINGSESSION'],\n",
       "    'data': []},\n",
       "   'securities.cursor': {'metadata': {'INDEX': {'type': 'int64'},\n",
       "     'TOTAL': {'type': 'int64'},\n",
       "     'PAGESIZE': {'type': 'int64'}},\n",
       "    'columns': ['INDEX', 'TOTAL', 'PAGESIZE'],\n",
       "    'data': [[0, 0, 10000]]},\n",
       "   'securities.dates': {'metadata': {'from': {'type': 'date',\n",
       "      'bytes': 30,\n",
       "      'max_size': 0},\n",
       "     'till': {'type': 'date', 'bytes': 30, 'max_size': 0}},\n",
       "    'columns': ['from', 'till'],\n",
       "    'data': [[None, None]]}}],\n",
       " 164: [MoexApi(url_faq='http://iss.moex.com/iss/reference/164', url_template='http://iss.moex.com/iss/history/engines/stock/totals/boards/{board}/securities/{security}', description='Обобщенная информация по фондовому рынку по выбранному режиму и инструменту'),\n",
       "  {'security': {'metadata': {'SECID': {'type': 'string',\n",
       "      'bytes': 36,\n",
       "      'max_size': 0},\n",
       "     'TRADEDATE': {'type': 'date', 'bytes': 10, 'max_size': 0},\n",
       "     'BOARDID': {'type': 'string', 'bytes': 12, 'max_size': 0},\n",
       "     'CURRENCYID': {'type': 'string', 'bytes': 9, 'max_size': 0},\n",
       "     'OPEN': {'type': 'double'},\n",
       "     'HIGH': {'type': 'double'},\n",
       "     'LOW': {'type': 'double'},\n",
       "     'CLOSE': {'type': 'double'},\n",
       "     'WAPRICE': {'type': 'double'},\n",
       "     'MARKETPRICE2': {'type': 'double'},\n",
       "     'ADMITTEDQUOTE': {'type': 'double'},\n",
       "     'TRENDCLOSE': {'type': 'double'},\n",
       "     'TRENDWAP': {'type': 'double'},\n",
       "     'TRENDWAPPR': {'type': 'double'},\n",
       "     'VOLUME': {'type': 'double'},\n",
       "     'VALUE': {'type': 'double'},\n",
       "     'NUMTRADES': {'type': 'int32'},\n",
       "     'OPENVAL': {'type': 'double'},\n",
       "     'CLOSEVAL': {'type': 'double'},\n",
       "     'ISSUESIZE': {'type': 'double'},\n",
       "     'FACEVALUE': {'type': 'double'},\n",
       "     'DAILYCAPITALIZATION': {'type': 'double'},\n",
       "     'MONTHLYCAPITALIZATION': {'type': 'double'},\n",
       "     'MP2VALTRD': {'type': 'double'},\n",
       "     'ADMITTEDVALUE': {'type': 'double'},\n",
       "     'MARKETPRICE3': {'type': 'double'},\n",
       "     'MARKETPRICE3TRADESVALUE': {'type': 'double'},\n",
       "     'LISTNAME': {'type': 'string', 'bytes': 6, 'max_size': 0},\n",
       "     'SYSTIME': {'type': 'datetime', 'bytes': 19, 'max_size': 0},\n",
       "     'TRADINGSESSION': {'type': 'int32'}},\n",
       "    'columns': ['SECID',\n",
       "     'TRADEDATE',\n",
       "     'BOARDID',\n",
       "     'CURRENCYID',\n",
       "     'OPEN',\n",
       "     'HIGH',\n",
       "     'LOW',\n",
       "     'CLOSE',\n",
       "     'WAPRICE',\n",
       "     'MARKETPRICE2',\n",
       "     'ADMITTEDQUOTE',\n",
       "     'TRENDCLOSE',\n",
       "     'TRENDWAP',\n",
       "     'TRENDWAPPR',\n",
       "     'VOLUME',\n",
       "     'VALUE',\n",
       "     'NUMTRADES',\n",
       "     'OPENVAL',\n",
       "     'CLOSEVAL',\n",
       "     'ISSUESIZE',\n",
       "     'FACEVALUE',\n",
       "     'DAILYCAPITALIZATION',\n",
       "     'MONTHLYCAPITALIZATION',\n",
       "     'MP2VALTRD',\n",
       "     'ADMITTEDVALUE',\n",
       "     'MARKETPRICE3',\n",
       "     'MARKETPRICE3TRADESVALUE',\n",
       "     'LISTNAME',\n",
       "     'SYSTIME',\n",
       "     'TRADINGSESSION'],\n",
       "    'data': []},\n",
       "   'security.cursor': {'metadata': {'INDEX': {'type': 'int64'},\n",
       "     'TOTAL': {'type': 'int64'},\n",
       "     'PAGESIZE': {'type': 'int64'}},\n",
       "    'columns': ['INDEX', 'TOTAL', 'PAGESIZE'],\n",
       "    'data': [[0, 0, 5000]]},\n",
       "   'security.dates': {'metadata': {'from': {'type': 'date',\n",
       "      'bytes': 30,\n",
       "      'max_size': 0},\n",
       "     'till': {'type': 'date', 'bytes': 30, 'max_size': 0}},\n",
       "    'columns': ['from', 'till'],\n",
       "    'data': [[None, None]]}}],\n",
       " 715: [MoexApi(url_faq='http://iss.moex.com/iss/reference/715', url_template='http://iss.moex.com/iss/statistics/engines/currency/markets/fixing/{security}', description='Фиксинги Московской биржи'),\n",
       "  {'history': {'metadata': {'tradedate': {'type': 'date',\n",
       "      'bytes': 10,\n",
       "      'max_size': 0},\n",
       "     'secid': {'type': 'string', 'bytes': 36, 'max_size': 0},\n",
       "     'rate': {'type': 'double'}},\n",
       "    'columns': ['tradedate', 'secid', 'rate'],\n",
       "    'data': []},\n",
       "   'history.cursor': {'metadata': {'INDEX': {'type': 'int64'},\n",
       "     'TOTAL': {'type': 'int64'},\n",
       "     'PAGESIZE': {'type': 'int64'}},\n",
       "    'columns': ['INDEX', 'TOTAL', 'PAGESIZE'],\n",
       "    'data': [[0, 0, 100]]},\n",
       "   'history.dates': {'metadata': {'from': {'type': 'date',\n",
       "      'bytes': 30,\n",
       "      'max_size': 0},\n",
       "     'till': {'type': 'date', 'bytes': 30, 'max_size': 0}},\n",
       "    'columns': ['from', 'till'],\n",
       "    'data': [[None, None]]}}],\n",
       " 712: [MoexApi(url_faq='http://iss.moex.com/iss/reference/712', url_template='http://iss.moex.com/iss/statistics/engines/futures/markets/indicativerates/securities/{security}', description='Индикативный курс валют срочного рынка'),\n",
       "  {'securities': {'metadata': {'tradedate': {'type': 'date',\n",
       "      'bytes': 10,\n",
       "      'max_size': 0},\n",
       "     'tradetime': {'type': 'string', 'bytes': 24, 'max_size': 0},\n",
       "     'secid': {'type': 'string', 'bytes': 36, 'max_size': 0},\n",
       "     'rate': {'type': 'double'}},\n",
       "    'columns': ['tradedate', 'tradetime', 'secid', 'rate'],\n",
       "    'data': []},\n",
       "   'securities.cursor': {'metadata': {'INDEX': {'type': 'int64'},\n",
       "     'TOTAL': {'type': 'int64'},\n",
       "     'PAGESIZE': {'type': 'int64'}},\n",
       "    'columns': ['INDEX', 'TOTAL', 'PAGESIZE'],\n",
       "    'data': [[0, 0, 100]]},\n",
       "   'securities.dates': {'metadata': {'from': {'type': 'date',\n",
       "      'bytes': 30,\n",
       "      'max_size': 0},\n",
       "     'till': {'type': 'date', 'bytes': 30, 'max_size': 0}},\n",
       "    'columns': ['from', 'till'],\n",
       "    'data': [[None, None]]}}],\n",
       " 861: [MoexApi(url_faq='http://iss.moex.com/iss/reference/861', url_template='http://iss.moex.com/iss/analyticalproducts/curves/securities/{security}', description='Будущие ставки для ценообразования нестандартных инструментов (деривативов)'),\n",
       "  {'curves': {'metadata': {'tradedate': {'type': 'date',\n",
       "      'bytes': 10,\n",
       "      'max_size': 0},\n",
       "     'tradetime': {'type': 'time', 'bytes': 10, 'max_size': 0},\n",
       "     'group': {'type': 'string', 'bytes': 75, 'max_size': 0},\n",
       "     'secid': {'type': 'string', 'bytes': 75, 'max_size': 0},\n",
       "     'term': {'type': 'string', 'bytes': 15, 'max_size': 0},\n",
       "     'value': {'type': 'double'},\n",
       "     'systime': {'type': 'datetime', 'bytes': 19, 'max_size': 0}},\n",
       "    'columns': ['tradedate',\n",
       "     'tradetime',\n",
       "     'group',\n",
       "     'secid',\n",
       "     'term',\n",
       "     'value',\n",
       "     'systime'],\n",
       "    'data': []}}]}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n"
     ]
    }
   ],
   "source": [
    "display(EMPTY_RESP_API)\n",
    "print(len(EMPTY_RESP_API))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0493e7a5",
   "metadata": {},
   "source": [
    "### Пройдемся по id-шникам\n",
    "\n",
    "- 158. Нет описания\n",
    "- 759. Нет описания\n",
    "- 149. Играл руками. НЕ получается вытянуть показатели и статистику бумаги участвующей в индексе. Возможно нужен перебор (возможно, работает только с какими-то опредленными индексами)\n",
    "- 163. Играл с кучей кодов режимов. Всегда возвращет пустоту. Невозможно получить обобщенную инфу.\n",
    "- 164. Аналогично с 163, но с деталями по бумаге. Пустота\n",
    "- 715. Нужен код фиксинга и заработает. Исправляю ниже.\n",
    "- 712. Нужен код индикативного курса валют. Похоже secid ~ USD/RUR (т.е. через знак черты '/'). Исправляю ниже.\n",
    "- 861. Нужен код ПФИ. Исправлю ниже"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "02c1fc56",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = EMPTY_RESP_API.pop(715)\n",
    "resp = requests.get(data[0].url_template.format(security=\"EURFIXME\") + '.json')\n",
    "save_result(resp.json(), 715)\n",
    "OK_API[715] = data[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "3ca954c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = EMPTY_RESP_API.pop(712)\n",
    "resp = requests.get(data[0].url_template.format(security=\"USD/RUB\") + '.json')\n",
    "save_result(resp.json(), 712)\n",
    "OK_API[712] = data[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "13ac10d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = EMPTY_RESP_API.pop(861)\n",
    "resp = requests.get(data[0].url_template.format(security=\"ALRS-6.23\") + '.json')\n",
    "save_result(resp.json(), 861)\n",
    "OK_API[861] = data[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb9b51b9",
   "metadata": {},
   "source": [
    "# Финалочка:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "b30dfe67",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "151 43 107\n"
     ]
    }
   ],
   "source": [
    "all_api = len(FINAL_DATA)\n",
    "bad_api = len(UNAVAILABLE_API) + len(EMPTY_RESP_API) + len(ERROR_API) + len(BAD_API)\n",
    "good_api = len(OK_API)\n",
    "print(all_api, bad_api, good_api)  # Потеряли api #789 т.к. там не подходит параметр. Эндпоинт с описанием полей."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1a37a2d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Большая часть остатка - по подписке или не работают. Малая часть - описание полей, которую можно пропустить.\n",
    "print(f\"Проверено {good_api} из {all_api} эндпоинтов. Или {good_api/all_api:.0%}.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "259d1245",
   "metadata": {},
   "source": [
    "## Итого:\n",
    "1. Мы получили список рабочих урлов и потенциально можем написать решение для быстрого и удобного их использования\n",
    "2. У нас есть большАя часть описания урлов.\n",
    "3. У нас есть примеры ответов, для быстрого изучения деталей."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f85ed848",
   "metadata": {},
   "source": [
    "## Планы:\n",
    "\n",
    "1. Собрать описание детальных параметров.\n",
    "2. Проверить их работоспособность.\n",
    "3. Подготовить инструмент быстрой работы с апи моекса"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "85b44995",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Save for next iteration\n",
    "import pickle\n",
    "save_pickle = {\n",
    "    \"use_api\": OK_API,\n",
    "    \"globals\": GLOBAL_GUID\n",
    "}\n",
    "with open('api.pickle', 'wb') as file:\n",
    "    pickle.dump(save_pickle, file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01100fc2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Необработанный формат ячейки",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
